利用DAO的API可以实现,一下代码摘自Diamond Access的例子代码,
它使用的就是DAO的接口:
var
dbname : string;
db : Database;
td : TableDef;
fld : Field;
idx : Index;
i : Integer;
name : string;
_type : Integer;
size : Integer;
begin
if InputQuery ('Database name', 'Enter database name', dbname) then
begin
db := __DBEngine.CreateDatabase (ExtractFilePath (Application.ExeName) + dbname, ';LANGID=0x0409;CP=1252;COUNTRY=0', 0);
td := db.CreateTableDef (Edit1.Text, 0, '', '');
for i := 1 to Grid.RowCount do
begin
name := Grid.Cells [1, i];
_type := GetTypeFromName (Grid.Cells [2, i]);
size := StrToIntDef (Grid.Cells [3, i], -1);
if (name <> '') and (size <> -1) then
begin
fld := td.CreateField (name, _type, size);
td.Fields.Append (fld);
end;
end;
db.TableDefs.Append (td);
db.Close;
ShowMessage ('Database ' + dbname + ' created.');
end;