Board index » delphi » Packing a dBASE IV database at run-tim

Packing a dBASE IV database at run-tim

I am converting a clipper application that I wrote some time ago into a Delphi
application. No problems so far (I very much like Delphi), but I am having a
devil of a time trying to figure out how to pack (permanently remove the
deleted records) the database at run-time. Can anybody tell me what I'm
missing here?

I don't want to empty the table, I just want to removed the records marked for
deletion. Thanks in advance.

 

Re:Packing a dBASE IV database at run-tim


Quote
Keith Peterson (kpet...@bernie.compusmart.ab.ca) wrote:

: I am converting a clipper application that I wrote some time ago into a
: Delphi
: application. No problems so far (I very much like Delphi), but I am having
: a
: devil of a time trying to figure out how to pack (permanently remove the
: deleted records) the database at run-time. Can anybody tell me what I'm
: missing here?

Here is what Steve Koterski (koter...@borland.com) wrote on 28 Jul 1995:

Quote
> To physically remove records from a dBASE table file that have been soft-
> deleted, you would need to use the BDE function DbiPackTable. The stock
> TTable component includes only those table features and operations com-
> mon to all table types natively supported. Idiosyncracies of only one
> table type were not provided for, and require special action. These soft-
> deletes are specific to dBASE tables.

> Here is an example of a unit that makes a call to the DbiPackTable func-
> tion. As when calling any BDE function, the BDE wrapper units DbiTypes,
> DbiErrs, and DbiProcs must be included in the Uses section of the unit
> that is to make a call to a BDE function.

> Example code follows...

> unit Pack_1;

> interface

> uses
>   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
>   Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables,
>   DbiTypes, DbiProcs, DbiErrs;

> type
>   TForm1 = class(TForm)
>     Table1: TTable;
>     DataSource1: TDataSource;
>     DBGrid1: TDBGrid;
>     Button1: TButton;
>     procedure Button1Click(Sender: TObject);
>     procedure FormShow(Sender: TObject);
>     procedure FormClose(Sender: TObject; var Action: TCloseAction);
>   private
>     { Private declarations }
>   public
>     { Public declarations }
>   end;

> var
>   Form1: TForm1;

> implementation

> {$R *.DFM}

> procedure TForm1.Button1Click(Sender: TObject);
> var
>   Error: DbiResult;
>   ErrorMsg: String;
>   Special: DBIMSG;
> begin
>   table1.Active := False;
>   try
>     Table1.Exclusive := True;
>     Table1.Active := True;
>     Error := DbiPackTable(Table1.DBHandle, Table1.Handle,
>                           nil, szdBASE, True);
>     Table1.Active := False;
>     Table1.Exclusive := False;
>   finally
>     Table1.Active := True;
>   end;
>   case Error of
>     DBIERR_NONE:
>       ErrorMsg := 'Successful';
>     DBIERR_INVALIDPARAM:
>       ErrorMsg := 'The specified table name or the pointer to the table ' +
>         'name is NULL';
>     DBIERR_INVALIDHNDL:
>       ErrorMsg := 'The specified database handle or cursor handle is ' +
>         'invalid or NULL';
>     DBIERR_NOSUCHTABLE:
>       ErrorMsg := 'Table name does not exist';
>     DBIERR_UNKNOWNTBLTYPE:
>       ErrorMsg := 'Table type is unknown';
>     DBIERR_NEEDEXCLACCESS:
>       ErrorMsg := 'The table is not open in exclusive mode';
>   else
>     DbiGetErrorString(Error, Special);
>     ErrorMsg := '[' + IntToStr(Error) + ']: ' + Special;
>   end;
>   MessageDlg(ErrorMsg, mtWarning, [mbOk], 0);
> end;

> procedure TForm1.FormShow(Sender: TObject);
> begin
>   Table1.Active := True;
> end;

> procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
> begin
>   Table1.Active := False;
> end;

> end.

Note that if you don't want to directly handle the exception that could occur
in DbiPackTable(), then you could simply use the following:

  Check( DbiPackTable(Table1.DBHandle, Table1.Handle, nil, szdBASE, True) );

[see the Check() procedure in Delphi's on-line help].

Also note that the last parameter to DbiPackTable() "specifies whether or not
to regenerate out-of-date table indexes. If TRUE, all out-of-date table
indexes are regenerated (applies to maintained indexes only). Otherwise,
out-of-date indexes are not regenerated" [Borland BDE (IDAPI) on-line
reference].

--
        loveseekstears
stoEhr  hopedeniesfate
        sorrowcannotbe

Re:Packing a dBASE IV database at run-tim


REfer to a document in delphi\docs\dbiprocs.int

YOu need to include 1 file in your app when compile, that is ->
dbiprocs.pas

Call this :

DbiPackTable(xxx, vvv, b, c, f)

refer to the document for xxx, vvv, b , c, f (it's not literal here!)

Or go www.borland.com -> developer -> technical FAQ (its all there)

Other Threads