想物理删除,也简单,Delphi提供了一个函数:dbiPackTable
uses BDE;
Check(DbiPackTable(Table1.DbHandle, Table1.Handle, Nil, szDBASE, TRUE));
uses BDE;
Check(DbiPackTable(Table1.DbHandle, Table1.Handle, Nil, szDBASE, TRUE));
调试欢乐多
按照你的方法,提示下列错误:
Invalid handle to the function
谢谢你再次帮忙!我用的是VFP数据库。
或者你查一下帮助,很好用的
代码如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
with Table1 do
begin
Active := False;
EmptyTable;
end;
Check(DbiPackTable(Table1.DBHandle, Table1.Handle, nil, szDBASE, True));
end;谢谢你
Check(DbiPackTable(Table1.DBHandle,Table1.Handle,Table1,Nil,True));
表必须打开
Check(DbiPackTable(Table1.DBHandle,Table1.Handle,Table1,Nil,True));
表必须打开并且独占
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)
感激不尽
Capability not supported!
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!
//打开显示内容 当然有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;
删除是删除了,我也可以删除了,但是没用彻底删除,你用MVFP打开可以看出,它只是做了删除标记,并没有释放空间。只有在操作了pack后,它才彻底删除。
我问的就是pack在delphi中怎样实现!
{ 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;
errResult := DbiPackTable( DbfTable.dbHandle,DbfTable.handle, NIL, NIL, true );
我的dbf使用table连接的(先用database)
你说的open是什么意思?是不是table1.active:=true?
还有个问题:只用操作该函数就删除了吗?用不用执行table1.emptytable后在执行该函数?
该函数与VFP中的"pack"应该是一样的吧!
谢谢
不用emptyTable
你再把第三个参数设为'Example.dbf',即带上名字,如果再不行,
估计Delphi删除不掉VFP的数据,只能删除Dbase、Paradox等的数据。
如果你解决了还望告知
谢谢!
还是不行
不过我想都说delphi的数据库处理能力好,不会连这个功能都不能实现吧!
谢谢你的关注,也希望你继续关注,问题解决了一定告诉你!
to all:
谁碰到过类似问题,帮帮小弟!!!
我发现我的VFP表不属于dBASE,所以出现下列错误:
Capability not supported! 有没有别的办法?
难道delphi真这样差么!!!