1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| // Déclarer les variables globales
var
Access, DataBase, TableDef, EnregSet: Variant;
// Déclarer le tableau de correspondance entre les champs Delphi et Access
arrMesBasesTypes: array[TFieldType] of Integer =
({dbText}10 {ftUnknown},
{dbText}10 {ftString},
{dbInteger}3 {ftSmallint},
{dbLong}4 {ftInteger},
{dbInteger}3 {ftWord},
{dbBoolean}1 {ftBoolean},
{dbDouble}7 {ftFloat},
{dbCurrency}5 {ftCurrency},
{dbDouble}7 {ftBCD},
{dbDate}8 {ftDate},
{dbDate}8 {ftTime},
{dbDate}8 {ftDateTime},
{dbLongBinary}11 {ftBytes},
{dbLongBinary}11 {ftVarBytes},
{dbInteger}3 {ftAutoInc},
{dbLongBinary}11 {ftBlob},
{dbMemo}12 {ftMemo},
{dbLongBinary}11 {ftGraphic},
{dbMemo}12 {ftFmtMemo},
{dbLongBinary}11 {ftParadoxOle},
{dbLongBinary}11 {ftDBaseOle},
{dbBinary}9 {ftTypedBinary},
{dbText}10 {ftCursor}
{$IFDEF VER120}
,
{dbText}10 {ftFixedChar},
{dbText}10 {ftWideString},
{dbBigInt}16 {ftLargeint},
{dbText}10 {ftADT},
{dbText}10 {ftArray},
{dbText}10 {ftReference},
{dbText}10 {ftDataSet}
{$ELSE}
{$IFDEF VER125}
,
{dbText}10 {ftFixedChar},
{dbText}10 {ftWideString},
{dbBigInt}16 {ftLargeint},
{dbText}10 {ftADT},
{dbText}10 {ftArray},
{dbText}10 {ftReference},
{dbText}10 {ftDataSet}
{$ELSE}
{$IFDEF VER130}
,
{dbText}10 {ftFixedChar},
{dbText}10 {ftWideString},
{dbBigInt}16 {ftLargeint},
{dbText}10 {ftADT},
{dbText}10 {ftArray},
{dbText}10 {ftReference},
{dbText}10 {ftDataSet},
{dbLongBinary}11 {ftOraBlob},
{dbLongBinary}11 {ftOraClob},
{dbText}10 {ftVariant},
{dbText}10 {ftInterface},
{dbText}10 {ftIDispatch},
{dbGUID}15 {ftGuid}
{$ENDIF}
{$ENDIF}
{$ENDIF});
// Maintenant on peut bosser avec...
procedure ChargeAdo;
try
Access := GetActiveOleObject('DAO.DBEngine.35');
except
Access := CreateOleObject('DAO.DBEngine.35');
end;
procedure OuvrirMdb;
try
database := access.OpenDatabase(yourDatabaseName);
except
exit
end;
procedure NouvelleTable;
begin
Tabledef := Database.CreatetableDef(NomdeMatable, 0, '', '');
end;
//Ajouter une description de champ
procedure AjoutDescroChamp;
begin
Tabledef.Fields.Append(Tabledef.CreateField(StrFieldName, arrMesBasesTypes[intDataType], Size));
end;
procedure OuvrirTable;
begin
EnregSet := Database.Opentable(LeNomdeMaTable, 0);
end;
// Ajout d'un enregistrement
procedure AppendEnreg;
begin
Recordset.Addnew;
end;
//Détruire l'objet Ado
procedure DestroyAdo;
begin
Access := Unassigned;
end; |
Partager