彻底删除dBASE Table
如何维维DBF维数据
事上,由于维维维维维Delphi维维维维维维维具有快捷易用、功能大等点,使得很多强FoxPro和VFP维维维维维维维维的程序人加入到了Delphi维维。但在FoxPro和VFP维维维维维维维维维的境下,有多DBF维型的数据表文件需要移植到Delphi中来,因此在Delphi维维维维维维维维维维维维维维维维维维维维维维维维维中如何和操作些数据将是一个很重要的。下面述在Delphi中完成DBF维维数据的如下操作:真正除、示被除、取当前号和恢被除,维维维维维维维维维维维维维维维维维维维维维维维维维维维维维
1. 维维维维真正除
在Delphi程序中,使用Table或Query维件的Delete维维维维维维维维维维维维维维维维维维方法行除操作,系行的是
除,即相当于Foxpro“中的Set Delete Off”维维维维维维维维维维维维维维维维维维维的效果。方法只是将用星号除,
并没有行物理上的除。要想真正除,需要用维维维维维维维维维维维维维维维维维维维维维维BDE函数DbiPackTable维维维维维维维,函数法:functionDbiPackTable(hDb:hDBIDb;hCursor:hDBICur;pszTableName:PChar;pszDriverType
:PChar;bRegenIdxs:Bool):DBIResult;
其中hDb维维数据Databse的句柄,hCursor维数据表Table的句柄,pszTableName维维维维维维维维要除的数据表名,pszDriverType维维维维维维维维维维维维维要除的数据表的型,bRegenIdxs维维维维维维维维维维表示是否在除后自更新索引文件。在四个参数中,hDb维不能NULL。hCursor、pszTableName、pszDriverType维可以NULL,但必维维维维维维维维维维维维维维维维维维维维提供足的信息来数据表的文件名和型,当hCursor维维维维不空,pszTableName和pszDriverType维可以NULL,当pszTableName维维维数据表的路径和文件名,hCursor和pszDriverType维可以NULL。
维维维维维维维维维维得注意的是,在除,如果用Table维维维维来,Table维维必以Exclusive=True维维的方式打。2. 维维维维维维维维示或不示除
当DBF维维维维维维维维维维维维维维维维维维数据中的行除后,默情况下在DBGrid维维维维维维维维维维维维维维维等数据示件中是看不些的。可以用BDE维维函数来控制是否示DBF维维维维维维维维维维维维维数据中被除的,如同在Foxpro维维中利用句Set Delete ON/OFF维维维维维维维维维维维维维维一。行一功能的函数DbiSetProp维维维维 ,其法:
functionDbiSetProp(hObj:hDBIObj;iProp:Longint;iPropValue:Longint):DBIResult;
维维维函数用来置DBI维维维维维象中某个属性的。其中Obj维DBI维维维维维维维象名称,里数据表Table的句柄,iProp维属性名,可使用除属性维维维维维curSOFTDELETEON,iPropValue维维维属性。
3. 维维维维取当前号
在Delphi中可以使用BDE维维维维维维维维维维维维维维维维维维维维函数取当前在数据集中的号,函数DbiGetRecord维维维维,其法:functionDbiGetRecord(hCursor:hDBICur;eLock:DBILockType;pRecBuff:Pointer;precProp
s:pRECProps):DBIResult;
维维维维维维维维维维维维函数用来取得当前的一些属性。其中,hCursor维数据集的Handle,eLock维维维维维维维维加的型,pRecBuff维维维维维维维存放的冲区,precProps维维维维维维维维维维维维维维维维维维属性集,里面就包含当前的号。
4. 维维维维维维恢除
在Delphi维维用程序中,DBF维维维维维维维维维维维维维维维维维维维维维维维维数据表行的除操作除操作。由于物理并没有从
数据表中除,因此可以恢被除的,只要去掉除志即可。完成一功能需使用函数维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维维DbiUndeleteRecord维维维维,其法:
functionDbiUndeleteRecord(hCursor:hDBICur):DBIResult;其中,hCursor可以是数据集的Handle。
以下底除维维维维维Paradox 和dBASE Table维维维的代
// Pack a Paradox or dBASE table // The table must be opened execlusively before calling this
function...
procedure PackTable(Table: TTable);
var
Props: CURProps;
hDb: hDBIDb;
TableDesc: CRTblDesc;
begin
// Make sure the table is open exclusively so we can get the db handle...
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 ');
// Get the table properties to determine table type...
Check(DbiGetCursorProps(Table.Handle, Props));
// If the table is a Paradox table, you must call DbiDoRestructure...
if Props.szTableType = szPARADOX then begin
// Blank out the structure...
FillChar(TableDesc, sizeof(TableDesc), 0);
// Get the database handle from the table 's cursor handle...
Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
// Put the table name in the table descriptor...
StrPCopy(TableDesc.szTblName, Table.TableName);
// Put the table type in the table descriptor...
StrPCopy(TableDesc.szTblType, Props.szTableType);
// Set the Pack option in the table descriptor to TRUE...
TableDesc.bPack := True;
// Close the table so the restructure can complete...
Table.Close;
// Call DbiDoRestructure...
Check(DbiDoRestructure(hDb, 1, @TableDesc,
nil, nil, nil, False));
end
else
// If the table is a dBASE table, simply call DbiPackTable...
if (Props.szTableType = szDBASE) then
Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, True))
else
// Pack only works on PAradox or dBASE; nothing else...
raise EDatabaseError.Create( 'Table must be either of Paradox or dBASE ' +
'type to pack ');
Table.Open;
end;