想物理删除,也简单,Delphi提供了一个函数:dbiPackTable
uses BDE;
Check(DbiPackTable(Table1.DbHandle, Table1.Handle, Nil, szDBASE, TRUE));

解决方案 »

  1.   

    to guoyuzhang:
    按照你的方法,提示下列错误:
    Invalid handle to the function
    谢谢你再次帮忙!我用的是VFP数据库。
      

  2.   

    你把代码贴上来看看吧,另外你uses BDE 了吗?
      

  3.   

    你把代码贴上来看看吧,另外你uses BDE 了吗?
    或者你查一下帮助,很好用的
      

  4.   

    我查帮助了,还是不行,我也加上uses BDE 了
    代码如下:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with Table1 do
      begin
      Active := False;
      EmptyTable;
      end;
      Check(DbiPackTable(Table1.DBHandle, Table1.Handle, nil, szDBASE, True));
    end;谢谢你
      

  5.   

    if not active then open;
    Check(DbiPackTable(Table1.DBHandle,Table1.Handle,Table1,Nil,True));
    表必须打开
      

  6.   

    if not active then open;
    Check(DbiPackTable(Table1.DBHandle,Table1.Handle,Table1,Nil,True));
    表必须打开并且独占
      

  7.   

    to guoyuzhang:
     procedure TForm1.Button1Click(Sender: TObject);
    begin
      with Table1 do
      begin
      Active := False;
      EmptyTable;
      active:=true;
      Exclusive := true;
      end;
      Check(DbiPackTable(Table1.DBHandle, Table1.Handle, nil, szDBASE, True));
    end;还是不行。
    我用的是odbc连接(microsoft foxpro VFP driver)
    感激不尽
     
      

  8.   

    现在提是错误是:
    Capability not supported!
      

  9.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      table1.EmptyTable;
      packtable(table1);
    end;
    procedure TForm1.PackTable(Table: TTable);
    begin
      if not Table.Active then
        raise EDatabaseError.Create('Table must be opened to pack');
      if not Table.Exclusive then
        raise EDatabaseError.Create('Table must be opened exclusively to pack');
      Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, True));
      Table.Open;
    end;提示错误是:
    Capability not supported! 
      

  10.   

    你们的讨论让我有点糊涂,用下面的代码就可以实现对DBF库文件的删除
    //打开显示内容 当然有TDBGrid和TDataSource控件
    procedure TForm1.BtnOpenClick(Sender: TObject);
    begin
      Table1.TableName :='nfpy_yxt.dbf';
      Table1.Active :=True;
    end;//删除DBF的内容
    procedure TForm1.BtnDeleteClick(Sender: TObject);
    begin
      with Table1 do
        begin
          if Active then close;
          EmptyTable;
        end;
    end;
      

  11.   

    to cyberjohn:
      删除是删除了,我也可以删除了,但是没用彻底删除,你用MVFP打开可以看出,它只是做了删除标记,并没有释放空间。只有在操作了pack后,它才彻底删除。
    我问的就是pack在delphi中怎样实现!
      

  12.   

    ---- 值 得 注 意 的 是, 在 删 除 记 录 时, 如 果 用Table 来 实 现, 则Table 必 须 以Exclusive=True 的 方 式 打 开 . 下 面 就 是 一 个 典 型 的 例 子 . 首先,应在uses语句加上DbiTypes,DbiProcs,DbiErrs.
    { Pack一个DBF数据表,DbfTable包含了数据表的信息 }
    function PackDbfTable( DbfTable : TTable ) : boolean;
    var
       errResult : DBIResult;
    begin
         if not DbfTable.Exclusive then 
    {如果不是以独占方式,操作失败 }
    begin
         result := false;
         exit;
    end;
         {进行删除操作 }
         errResult := DbiPackTable( DbfTable.dbHandle,
        DbfTable.handle, NIL, NIL, true );     {根据返回结果,返回成功与否的标志 }
         if errResult = DBIERR_NONE then
         {没有错误,操作成功 }
            result := true
         else{没有错误,操作失败 }
    result := false;
    end;
    注意,你的dbf最好用Table连接,并且要Open;
      

  13.   

    还是不行:调试通过,单步执行发现下句的errResult值总是为{没有错误,操作失败 }!!!
    errResult := DbiPackTable( DbfTable.dbHandle,DbfTable.handle, NIL, NIL, true );
        
    我的dbf使用table连接的(先用database)
    你说的open是什么意思?是不是table1.active:=true?
    还有个问题:只用操作该函数就删除了吗?用不用执行table1.emptytable后在执行该函数?
    该函数与VFP中的"pack"应该是一样的吧!
    谢谢
      

  14.   

    open是active := True
    不用emptyTable
    你再把第三个参数设为'Example.dbf',即带上名字,如果再不行,
    估计Delphi删除不掉VFP的数据,只能删除Dbase、Paradox等的数据。
    如果你解决了还望告知
    谢谢!
      

  15.   

    to guoyuzhang:
       还是不行
       不过我想都说delphi的数据库处理能力好,不会连这个功能都不能实现吧!
       谢谢你的关注,也希望你继续关注,问题解决了一定告诉你!
    to all:
       谁碰到过类似问题,帮帮小弟!!!
      

  16.   

     DbiPackTable函数只支持 Paradox or dBASE数据库
    我发现我的VFP表不属于dBASE,所以出现下列错误:
    Capability not supported! 有没有别的办法?
    难道delphi真这样差么!!!