infopower的工具集中有个TWWTable能够对paradox和DBase的表PACK.
这是他的源码:
Function TwwTable.Pack(var statusMsg: string): boolean;
var
rslt: DBIResult;
szErrMsg: DBIMSG;
pTblDesc: pCRTblDesc;
bExclusive: Boolean;
bActive: Boolean;
isParadox, isdBASE: boolean;
tempTableName: string;
props: CurProps; { Preserve password }
begin
Result:= False;
StatusMsg:= '';
if TableType = ttDefault then begin
tempTableName:= tablename;
tempTableName:= lowercase(tempTablename);
isParadox := (pos('.db', tempTableName)>0) and
(tempTableName[length(tempTableName)]='b');
isDBASE:= pos('.dbf', temptableName)>0;
end
else begin
isParadox:= TableType = ttParadox;
isDBASE:= TableType = ttDBASE;
end;
if isParadox or isdBASE then begin
bExclusive:= Exclusive;
bActive:= Active;
DisableControls;
Close;
Exclusive:= True;
end
else begin
StatusMsg:= 'Invalid table type for packing.';
exit;
end;
if isParadox then begin
if wwMemAvail(Sizeof(CRTblDesc)) then begin
StatusMsg:= 'Cannot pack table. Insufficient memory. ';
end
else begin
GetMem(pTblDesc, SizeOf(CRTblDesc));
FillChar(pTblDesc^, SizeOf(CRTblDesc), 0);
with pTblDesc^ do begin
strPCopy(szTblName, Tablename);
strPCopy(szTblType, szParadox);
{ Check if table is password protected }
active:= True;
check(dbiGetCursorProps(Handle, props));
bProtected:= props.bProtected;
active:= False;
bPack:= True;
end;
Screen.cursor:= crHourGlass;
SetDBFlag(dbfOpened, True);
rslt:= dbiDoRestructure(DBHandle, 1, pTblDesc, nil, nil, nil, False);
if rslt <> DBIERR_NONE then begin
dbiGetErrorString(rslt, szErrMsg);
statusMsg:= szErrMsg;
end
else result:= True;
SetDBFlag(dbfOpened, False);
FreeMem(pTblDesc, SizeOf(CRTblDesc) );
Screen.cursor:= crDefault;
end
end
else if isdBASE then begin
Screen.cursor:= crHourGlass;
Open;
rslt:= dbiPackTable(DBHandle, Handle, nil, nil, True);
Screen.cursor:= crDefault;
if rslt <> DBIERR_NONE then begin
dbiGetErrorString(rslt, szErrMsg);
statusMsg:= szErrMsg;
end
else result:= True;
end;
Close;
Exclusive:= bExclusive;
Active:= bActive;
EnableControls;
end;
--------------------------------------------------
对*.DBF这样的文件型数据库表你可以将原表有效的数据提取,
复制到同样结构的新表中,复制数据,删除原有的文件。修改
新表名称。这是个笨办法。
我在开发项目中遇到同样的问题,但是是INTRBASE数据库,就是
使用的复制数据库的办法。现在INTRBASE提供了原码,但是我还
没有搞明白。你们要是有办法就通知我。