我曾经使用过Diamond Access 1.90在程序中建立过Access的数据库文件。
该控件中也包含了一个样例,你参考以下,希望能对你有所帮助。
下附建立数据库的代码:
procedure TMainFrm.Button1Click(Sender: TObject);
var
dbname: string;
db: Database;
td: TableDef;
idx: Index;
rel: Relation;
begin
if InputQuery ('Database name', 'Enter database name', dbname) then
begin
if __DBEngine35 = nil then CreateEngine (Dao35, '');
db := __DBEngine35.CreateDatabase (ExtractFilePath (Application.ExeName) + dbname, ';LANGID=0x0409;CP=1252;COUNTRY=0', 0);
td := db.CreateTableDef ('Orders', 0, '', '');
td.Fields.Append (td.CreateField ('Order_ID', dbInteger, 0));
td.Fields.Append (td.CreateField ('Order_DATE', dbDate, 0));
td.Fields.Append (td.CreateField ('Order_CLIENT', dbText, 50));
td.Fields.Append (td.CreateField ('Order_TOTAL', dbCurrency, 0));
idx := td.CreateIndex ('Primary');
idx.Primary := True;
idx.Fields.Append (idx.CreateField ('Order_ID', dbInteger, 0));
td.Indexes.Append (idx);
idx := td.CreateIndex ('By_Client');
idx.Fields.Append (idx.CreateField ('Order_CLIENT', dbText, 50));
td.Indexes.Append (idx);
db.TableDefs.Append (td);
td := db.CreateTableDef ('Items', 0, '', '');
td.Fields.Append (td.CreateField ('Item_ID', dbInteger, 0));
td.Fields.Append (td.CreateField ('Order_ID', dbInteger, 0));
td.Fields.Append (td.CreateField ('Item_NAME', dbText, 40));
td.Fields.Append (td.CreateField ('Item_COUNT', dbInteger, 0));
td.Fields.Append (td.CreateField ('Item_PRICE', dbCurrency, 0));
idx := td.CreateIndex ('Primary');
idx.Primary := True;
idx.Fields.Append (idx.CreateField ('Item_ID', dbInteger, 0));
td.Indexes.Append (idx);
idx := td.CreateIndex ('By_Order');
idx.Fields.Append (idx.CreateField ('Order_ID', dbInteger, 0));
td.Indexes.Append (idx);
db.TableDefs.Append (td);
rel := db.CreateRelation ('ItemsOrders', 'Orders', 'Items', dbRelationUpdateCascade);
rel.Fields.Append (rel.CreateField ('Order_ID', dbInteger, 0));
rel.Fields ['Order_ID'].ForeignName := 'Order_ID';
db.Relations.Append (rel);
db.Close;
end;
end;
end.