Oczywiście jest to możliwe. :-)
Tabela musi być otwarta w trybie Exclusive. Przy okazji odświeżane są wszystkie indeksy. Przedstawiona procedura działa na tabelach Paradox i DBase. W bloku deklaracji (uses) trzeba zadeklarować BDE.
procedure PackTable (Table :TTable);
var
Props : CURProps;
hDb : hDBIDb;
TableDesc : CRTblDesc;
begin
if Table.Active = False
then raise EDatabaseError.Create ('Table must be opened to pack');
if Table.Exclusive = False
then raise EDatabaseError.Create ('Table must be opened exclusively to pack');
Check (DbiGetCursorProps (Table.Handle, Props));
if Props.szTableType = szPARADOX
then begin
FillChar (TableDesc, sizeof(TableDesc), 0);
Check (DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
StrPCopy (TableDesc.szTblName, Table.TableName);
StrPCopy (TableDesc.szTblType, Props.szTableType);
TableDesc.bPack:=True;
Table.Close;
Check (DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
end
else if Props.szTableType = szDBASE
then Check (DbiPackTable (Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))
else raise EDatabaseError.Create ('Table must be either of Paradox or dBASE type to pack');
Table.Open;
end;