.NET Zip component, Delphi Zip component, Barcode .NET, BDE Replacement and other .NET and Delphi components from ComponentAce
Products Download Order Contact us

Search
 

Delphi/C++ Components
.NET Components
ActiveX Controls
Kylix Components

Download

Download
Download Commercial
Trial Limitations

Support

Submit Request
Support Options

Order

Purchase
Competitive Upgrade
Premium Support
Sales Policy
Upgrade Policy
License Types

Info

News
Mailing List
Articles
Testimonials



About Us
Partners
Links
Contact Us
Link to Us





Home > Delphi/C++ Components > Absolute Database > Search Records Delphi Example

Absolute Database

Overview | Features | Requirements | Testimonials | SQL Samples | Code Samples | Screenshots | See Also | Download | Order
Search Records Delphi Example
Illustrates data searching using FindKey, Locate and Lookup methods.

Download Absolute Database | Learn more

unit uSearchRecords;

interface
{$I CompVer.inc}

uses
{$IFDEF D6H}
  Variants,
{$ENDIF}
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, DB, ABSMain, ComCtrls, ExtCtrls,
  Buttons;

const
  DataBaseFileName: String = '..\..\Data\Demos.abs';

type
  TForm1 = class(TForm)
    dbDemos: TABSDatabase;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Table: TABSTable;
    Button2: TButton;
    rgSMethod: TRadioGroup;
    gbLocateOptions: TGroupBox;
    cbPartKey: TCheckBox;
    cbCaseInSens: TCheckBox;
    Edit1: TEdit;
    GroupBox3: TGroupBox;
    mLog: TMemo;
    Label1: TLabel;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure rgSMethodClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  index:string;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 dbDemos.DatabaseFileName := ExtractFilePath(Application.ExeName) + DataBaseFileName;
 dbDemos.Open;
 Table.TableName := 'employee';
 Table.Open;
 mLog.Clear;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
 v: variant;
 info: string;
 Options: TLocateOptions;
begin
 info := '';
 mLog.Lines.Add(DateTimeToStr(Now));
 case rgSMethod.ItemIndex of
  0: begin
      Table.IndexName := 'ByFirstName';
      mLog.Lines.Add('< FindKey method >.  Search text: "' + Edit1.Text +'".');
      if (not Table.FindKey([Edit1.Text])) then
       mLog.Lines.Add(' Result: No records found.')
      else
       mLog.Lines.Add(' Result: Record found.');
      Table.IndexName := '';
     end;
  1: begin
      v := Table.Lookup('FirstName',Edit1.Text,'FirstName;LastName;PhoneExt');
      mLog.Lines.Add('< Lookup method >.  Search text: "' + Edit1.Text +'".');
      if (not VarIsNull(v)) then
       begin
        mLog.Lines.Add(' Result: Record found.');
        info := ' Info: FirstName is '+QuotedStr(String(v[0]));

        if (not VarIsNull(v[1])) then
         info := info + ', LastName is '+QuotedStr(String(v[1]))
        else
         info := info + ', LastName is '+QuotedStr('Null');

        if (not VarIsNull(v[2])) then
         info := info + ', PhoneExt is '+QuotedStr(String(v[2]))
        else
         info := info + ', PhoneExt is '+QuotedStr('Null');
        mLog.Lines.Add(info);
       end
      else
       mLog.Lines.Add('  Result: No records found.');
     end;
  2: begin
      mLog.Lines.Add('< Locate method >.  Search text: "' + Edit1.Text +'".');
      Options := [];
      if cbCaseInSens.Checked then
       begin
        Options := Options + [loCaseInsensitive];
        info := ' Options: CaseInSensitive = true'
       end
      else
       info := ' Options: CaseInSensitive = false';
      if cbPartKey.Checked then
       begin
        Options := Options + [loPartialKey];
        info := info + ', PartialKey = true.'
       end
      else
       info := info + ', PartialKey = false.';
      mLog.Lines.Add(info);
      if not Table.Locate('FirstName',Edit1.Text,Options) then
       mLog.Lines.Add(' Result: No records found.')
      else
       mLog.Lines.Add(' Result: Record found.');
     end;
 end;
 mLog.Lines.Add(' ')
end;

procedure TForm1.rgSMethodClick(Sender: TObject);
begin
 if rgSMethod.ItemIndex = 2 then
  begin
   cbCaseInSens.Enabled := true;
   cbPartKey.Enabled := true;
  end
 else
  begin
   cbCaseInSens.Enabled := false;
   cbPartKey.Enabled := false;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 mLog.Clear;
end;

end.



Search Records Delphi Example
Download Absolute Database | Learn more


Product Info


Current version: 7.95
Released: February 08, 2023
Price: $ 149

downloadorder


Our Customers



Testimonials

Thanks again for the superb tech support, I was worried I'd hit a brick wall this close to the finish line. Even working on the weekend... you guys rock!!!

Bob Boyd

        © 2003 - 2024 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Oct 06, 2024