Board index » delphi » Trying to pack table from the code (D1)

Trying to pack table from the code (D1)

        Are there any other possibilities of packing table than from Database
Desktop.
Probably it can be done by BDE in specific moments, but I had not faced
such one.

        I appreciate any help.

 

Re:Trying to pack table from the code (D1)


On Thu, 24 Jun 1999 23:46:32 GMT, "Michal Piasecki" <boxm...@friko.onet.pl>
wrote:

Quote
>Are there any other possibilities of packing table than from Database
>Desktop. Probably it can be done by BDE in specific moments, but I had
>not faced such one.

To pack a dBASE table from a Delphi application, you need to use the same
approach as the Database Desktop utility uses: a direct call to the BDE API
function DbiPackTable.

Below is an example of the DbiPackTable in use in a Delphi unit. This
example includes a demonstration of BDE error checking. BDE functions
return a value of type DBIResult that indicates the success or failure of
the function call, no error message will be generated by the BDE so this is
the only way to assess success. Any result but DBIERR_NONE indicates a
failure. With many BDE functions, failed calls cause a different return
code for different reasons for the failure. The various failure error codes
for the DbiPackTable function are demonstrated below.

unit Pack_1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables,
  BDE;

type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  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;

end.

For any unit making a call to BDE API functions, you must include the BDE
wrapper unit named BDE in the Uses section.

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski     "An inventor is a person who makes an ingenious
Felton, CA         arrangement of wheels, levers and springs, and believes
                   it civilization."          -- Ernest Dimnet (1866-1954)

Other Threads