Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do Pack Paradox tables at run time ? 3

Status
Not open for further replies.

RonR51

Programmer
Apr 19, 2001
18
AU
I would like to put a utility in my Delphi 5 database app that will pack the tables and free up the space from deleted records. I am using local Paradox tables in a single tier, single user situation.

The Database Desktop has a facility when you save tables but I can't find a method in either the TTable or TDataset components.

Can it be done, or do I have to copy the table, delete the old and rename the new.

RonR51
 
I don't have a full answer but packing the table is a function of the DBE. Look there for information on how to get this done.

cg Mahalo,
cg
 
At you will find a component complete with source that is a TTABLE replacement with additional functions to Pack (permanently remove deleted records) and regenerate indexes for DBase and Paradox tables.

X-)

Hope this sorts yoour problem Billy H

bhogar@acxiom.co.uk
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top