var table1:ttable;
begin
table1:=TTable.Create(nil);
if table1.active then table1.active:=false;
table1.close;
table1.databasename:=path+'data\sysdata';
table1.TableName:=('table1');
table1.FieldDefs.Clear;
table1.FieldDefs.Add('x',ftinteger,0,False);
table1.FieldDefs.Add('y',ftinteger,0,False);
table1.CreateTable;
table1.open;
end;
为什么以上操作只能执行一次,而第二次就提示:table1 busy?应该如何改?

解决方案 »

  1.   

    代码改改吧:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      databasepath,tablename: string;
      t1: TTable;
    begin
      t1 := TTable.create(self);
      with t1 do begin
       databasename:=edit2.text;
        tablename:= 'student';
        tabletype := ttparadox; //确定数据表名称
        with fielddefs do begin
           add('id',ftstring,6,true);
           add('name',ftstring,20,true);
           add('sex',ftstring,1,true);
           add('class',ftstring,4,false);
           add('department',ftsmallint,0,false);
           add('birthday',ftdate,0,false);
           add('native_place',ftstring,50,false);
       end;
        with IndexDefs do begin
          Clear;
          with AddIndexDef do begin
            Name := '';
            Fields := 'id';
            Options := [ixPrimary,ixunique];//设置主关键字
          end;
        end;
       createtable;
      end;
      t1.Free;
      showmessage('成功建立数据库在:'+edit2.text);
    end;