nit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, comobj,adox_tlb,Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
  Catalog: _Catalog;
  Table: _Table;
  Index : _Index;
  //FKey : _key;
  strCon:string;//定义连接字符串
  yourname:string;
  yourpwd:string;
begin
    yourname:=trim(edit1.Text);
    yourpwd:=trim(edit2.text);
    Catalog := CoCatalog.Create;
    strCon := 'Provider=Microsoft.Jet.OleDB.4.0;'
    //通过Jet OleDb直接操作Access数据库
    +'Data Source=c:\windows\desktop\'+yourname+'.mdb;'
    //数据库位置
    +'Jet OLEDB:Engine Type=5;'
    //Jet 4.x格式,如为4,则Jet 3.x格式
    +'Locale Identifier=0x0804;'
     //支持简体中文(一定要有)
    +'Jet OLEDB:Database Password='+yourpwd;//修改密码也在此;
    //加入密码
    Catalog.Create(strCon); //建立数据库
    {建立数据表和索引}
    Catalog.Set_ActiveConnection(strCon);
    //连接到数据库    with Catalog do
    begin //建立数据表
    Table:= CoTable.Create(); //建立Table实例    with Table do
    begin
    Name := 'MyTable1';    //建表 MyTable1
    Table.ParentCatalog := Catalog ;
    Columns.Append('ID',adInteger,8);
    
    Columns.Item['ID'].Properties.Item['AutoIncrement'].Value := true;
    
    Columns.Append('Name',adVarWChar,40);
    Columns.Append('Parent_ID',adInteger,8);
    Columns.Item['Parent_ID'].Properties['Default'].Value := 0;
                                           
    Columns.Append('Sort_ID',adInteger,8);
    Columns.Append('Counter',adInteger,8);
    Columns.Item['Counter'].Properties.Item['Default'].Value := 0;    //数据类型详见MDAC SDK
    Tables.Append(Table);  //建表 MyTable1    Index := CoIndex.Create() as _Index; //建立索引
    with Index do
    begin
    Name:='Idx1';
    PrimaryKey := True ;
    Unique := True;
    Columns.Append('ID',adInteger,8);
    _Release;
    end;
    Table.Indexes.Append(Index,EmptyParam);    Table._Release;
    Table:= CoTable.Create();
    end;           //with table do
    end;           //with catalog doend;