help : Physically deleteing DBF records in Delphi ?? 
Author Message
 help : Physically deleteing DBF records in Delphi ??

Hi. I'm new to delphi so i'm having troubles with it.
How can i physically delete recordes tha are marked as deleted in Dbf files (
in Clipper  PACK does it )
Thanx in advance.


Tue, 01 Sep 1998 03:00:00 GMT  
 help : Physically deleteing DBF records in Delphi ??

Quote:

> Hi. I'm new to delphi so i'm having troubles with it.
> How can i physically delete recordes tha are marked as deleted in Dbf files (
> in Clipper  PACK does it )
> Thanx in advance.

Hi... I'm also new to Delphi and since the product is so powerful,
I'll be learning it for quite awhile, however, as a previous
Clipper programmer(myself), I have preferred using the Successware
Apollo 2.0 component for accessing my clipper files.  It DOES have
a Pack function which was very reassuring.  Before I got Apollo, I
stuggled with the language and BDE calls by inserting code from
suggestion made on this board without really understanding
all of the reasons (if it works, I just do it) so

Enjoy..
Reece

Also the following is a suggestion offered in the past by
the suportive famous Borland Steve Koterski.  


Newsgroups: comp.lang.Pascal
Subject: Re: Delphi - PACK a dBase database
Date: 18 Apr 1995 17:19:38 GMT
Organization: Borland Intl

There is no built-in procedure equivalent to the dBASE-specific PACK
operation to rebuild a table without soft-deleted records. To do this in
Delphi, you will need to call the Borland Database Engine (BDE) function
DbiPackTable. This function is constructed as:

   DbiPackTable(hDb, hCursor, pszTableName, pszDriverType, bRegenIdxs)

Where:

1. hDb is a handle to the database. (In the case of an active TTable, use
   the DBHandle property.)
2. hCursor is a handle to the table. (Use the TTable's Handle property.)
3. pszTableName is a pointer to a string representing the name of the
   dBASE data file. (Use nil.)
4. pszDriverType is a pointer to the driver type. (Use szdBASE.)
5. bRegenIdxs is a boolean specifying whther to rebuild the associated
   indexes. (Use True.)

To use this function, you must include the BDE-related units in the unit
that will call this function. The units are: DbiTypes, DbiProcs, and
DbiErrs. Also, the table must be opened in exclusive mode.

Following is an example of the DbiPackTable function executed in the
OnClick event procedure of a TButton. The example deactivates the TTable,
set the Exclusive property, reactivates the TTable, calls the function,
resets Exclusive (if desired), and eventually resets the tables Active
property to true. The example also shows the possible return values for
DbiPackTable, how to use them, and how to trap for an error not in that
list.

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.

--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Newsgroups: comp.lang.pascal
Subject: Re: Delphi - PACK a dBase database
Date: 18 Apr 1995 17:19:38 GMT
Organization: Borland Intl

There is no built-in procedure equivalent to the dBASE-specific PACK
operation to rebuild a table without soft-deleted records. To do this in
Delphi, you will need to call the Borland Database Engine (BDE) function
DbiPackTable. This function is constructed as:

   DbiPackTable(hDb, hCursor, pszTableName, pszDriverType, bRegenIdxs)

Where:

1. hDb is a handle to the database. (In the case of an active TTable, use
   the DBHandle property.)
2. hCursor is a handle to the table. (Use the TTable's Handle property.)
3. pszTableName is a pointer to a string representing the name of the
   dBASE data file. (Use nil.)
4. pszDriverType is a pointer to the driver type. (Use szdBASE.)
5. bRegenIdxs is a boolean specifying whther to rebuild the associated
   indexes. (Use True.)

To use this function, you must include the BDE-related units in the unit
that will call this function. The units are: DbiTypes, DbiProcs, and
DbiErrs. Also, the table must be opened in exclusive mode.

Following is an example of the DbiPackTable function executed in the
OnClick event procedure of a TButton. The example deactivates the TTable,
set the Exclusive property, reactivates the TTable, calls the function,
resets Exclusive (if desired), and eventually resets the tables Active
property to true. The example also shows the possible return values for
DbiPackTable, how to use them, and how to trap for an error not in that
list.

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.

--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ Steve Koterski               _/   The opinions expressed here are    _/

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
             _/   The opinions expressed here are    _/

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/



Thu, 10 Sep 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Deleting Record Physically

2. Adding and deleteing BDE aliases in Delphi 1.0

3. DBF DBF DBF

4. Help: Converting DOS Clipper DBF's to Windows DBF's

5. HELP! DELPHI+DBF+NTX

6. How to delete a record physically from a dBase table ("pack")in Delphi?

7. Deleted DBF records

8. record lock with DBF

9. Deleted Records In DBF

10. Unable To Physically Commit to Paradox Database

11. Extract records to a new DBF Table

12. add/delete dbf record in pascal

 

 
Powered by phpBB® Forum Software