You don't have to reindex your indexes as long as you created them maintained. As far as packing goes, you don't need to pack Paradox tables (automatically done for you) and you DO need to pack dBASE tables.
This section demonstrates how to use the BDE to pack a dBASE table. Both dBASE and FoxPro let users mark a record for deletion. The only way to permanently remove marked records is with DbiPackTable. The BDE.DbiPackTable function is the method you use to pack a dBASE table. It optimizes table space by rebuilding the table associated with hCursor and releasing any free space. Exclusive access to the table is required and it must be opened.
Here is it's syntax:
function DbiPackTable (hDb: hDBIDb; hCursor: hDBICur; pszTableName: PChar; pszDriverType: PChar; bRegenIdxs: Bool): DBIResult stdcall;
Here are definitions of it's parameters:
- hDb Type: hDBIDb (Input) The database handle (TTable.Database.Handle)
- hCursor Type: hDBICur (Input) The cursor on the table (TTable.Handle). If hCursor is NULL, pszTableName and pszDriverType determine the table to be used.
- pszTableName Type: pCHAR (Input) Pointer to the table name.
- pszDriverType Type: pCHAR (Input) Pointer to the driver type.
- bRegenIdxs Type: BOOL (Input) True = recreate indexes; False = don't.
Here are the DbiResult return values:
- DBIERR_NONE The table was successfully rebuilt.
- DBIERR_INVALIDPARAM The specified table name or the pointer to the table name is NULL.
- DBIERR_INVALIDHNDL The specified database handle or cursor handle is invalid or NULL.
- DBIERR_NOSUCHTABLE Table name does not exist.
- DBIERR_UNKNOWNTBLTYPE Table type is unknown.
- DBIERR_NEEDEXCLACCESS The table is not open in exclusive mode.
Here is a sample usage (make sure DBTables and BDE are in your uses).
procedure TForm1.PackTable(Table : TTable; ReCreateIndexes : Boolean);
begin
// Make sure the table is open exclusively so we can get the db
// handle...
if not (Table.Active and Table.Exclusive) then
raise EDatabaseError.Create('Table must be opened exclusive to pack');
// DBTables.Check determines whether a value returned from the Borland
// Database Engine (BDE) represents an error condition. If a BDE error
// occurred, then DBTables.Check calls DbiError to raise an exception.
// BDE.DbiPackTable requires BDE to be in your uses.
Check(DbiPackTable(Table.Database.Handle, Table.Handle, Nil, Nil, ReCreateIndexes));
end;
Here is a sample method using the above method.
procedure TForm1.Button1Click(Sender: TObject);
begin
Table1.Active := False;
Table1.Exclusive := True;
Table1.Active := True;
PackTable(Table1, True);
end;