Chapter 29 of Delphi 4 Developer's Guide from
Steve Teixeira & Xavier Pacheco, deals with this problem
Here is unit in condensed form (I left the DBase stuff out)
which deals with paradox tables
unit DDGTbls;
{modified }
interface
uses DB, DBTables, BDE;
type
TParadoxTable = class(TTable)
private
protected
function CreateHandle: HDBICur; override;
function GetRecNum: Longint;
public
procedure Pack;
property RecNum: Longint read GetRecNum;
end;
implementation
uses SysUtils;
function TParadoxTable.CreateHandle: HDBICur;
{ Overridden from ancestor in order to perform a check to }
{ ensure that this is a Paradox table. }
var
CP: CURProps;
begin
Result := inherited CreateHandle; // do inherited
if Result <> Nil then begin
{ Get cursor properties, and raise exception if the }
{ table isn't using the Paradox driver. }
Check(dbiGetCursorProps(Result, CP));
if not (CP.szTableType = szPARADOX) then
raise EDatabaseError.Create('Not a Paradox table');
end;
end;
function TParadoxTable.GetRecNum: Longint;
{ Returns the sequence number of the current record. }
begin
UpdateCursorPos; // update BDE from Delphi
{ Get sequence number of current record into Result }
Check(dbiGetSeqNo(Handle, Result));
end;
procedure TParadoxTable.Pack;
var
TblDesc: CRTblDesc;
TempDBHandle: HDBIDb;
WasActive: Boolean;
begin
{ Initialize TblDesc record }
FillChar(TblDesc, SizeOf(TblDesc), 0); // fill with 0s
with TblDesc do begin
StrPCopy(szTblName, TableName); // set table name
szTblType := szPARADOX; // set table type
bPack := True; // set pack flag
end;
{ Store table active state. Must close table to pack. }
WasActive := Active;
if WasActive then Close;
try
{ Create a temporary database. Must be read-write/exclusive }
Check(dbiOpenDatabase(PChar(DatabaseName), Nil, dbiREADWRITE,
dbiOpenExcl, Nil, 0, Nil, Nil, TempDBHandle));
try
{ Pack the table }
Check(dbiDoRestructure(TempDBHandle, 1, @TblDesc, Nil, Nil, Nil,
False));
finally
{ Close the temporary database }
dbiCloseDatabase(TempDBHandle);
end;
finally
{ Reset table active state }
Active := WasActive;
end;
end;
end.
Hope this helps
Regards S. van Els
SAvanEls@cq-link.sr