- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


2979:Showing deleted records in a dBASE table.

KEYWORDS: deleted records display dBASE AREA: Database Programming

Q:   How can I view dBASE records marked for deletion. That is,
I want to view those records marked as "soft deletion"?

A:  In a dBASE table, records are not removed from the table
until the table is packed.  Until that happens, records that
are "deleted" are actually just marked as "to be" deleted. To
show these existing but not displayed records, the following
function, ShowDeleted(), makes use of a BDE API function,
DbiSetProp(), to show records marked for deletion.  It is not
necessary to close and re-open the table when using this
function.  ShowDeleted() takes a TTable and a boolean variable
as parameters. The boolean parameter determines whether or not
to show deleted records.

Example code follows:
-----

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids,
  DB, DBTables;

type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    CheckBox1: TCheckBox;
    procedure CheckBox1Click(Sender: TObject);
  public
    procedure ShowDeleted(Table: TTable; ShowDeleted: Boolean);
  end;

var
  Form1: TForm1;

implementation

uses DBITYPES, DBIERRS, DBIPROCS;

{$R *.DFM}

procedure TForm1.ShowDeleted(Table: TTable; ShowDeleted: Boolean);
var
  rslt: DBIResult;
  szErrMsg: DBIMSG;
begin
  Table.DisableControls;
  try
    Check(DbiSetProp(hDBIObj(Table.Handle), curSOFTDELETEON,
      LongInt(ShowDeleted)));
  finally
    Table.EnableControls;
  end;
  Table.Refresh;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  ShowDeleted(Table1, CheckBox1.Checked);
end;

end.

        TI



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile