home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / delphi / ODA10 / _SETUP.1 / DemoFastFind.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-06  |  3.5 KB  |  128 lines

  1. unit DemoFastFind;
  2.  
  3. interface
  4. uses
  5.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6.   StdCtrls, DBCtrls, Mask, ExtCtrls, DB, DBTables, DBCGrids;
  7.  
  8. type
  9.   TFormFastFind = class(TForm)
  10.     QryComp: TQuery;
  11.     SrcComp: TDataSource;
  12.     DBNavigator1: TDBNavigator;
  13.     DBCtrlGrid1: TDBCtrlGrid;
  14.     Pers_LastName: TDBEdit;
  15.     Pers_FirstName: TDBEdit;
  16.     Pers_Birthday: TDBText;
  17.     Pers_Remarks: TDBMemo;
  18.     BtnLookup: TButton;
  19.     BtnFindFirst: TButton;
  20.     EditFindText: TEdit;
  21.     QryCompPers_ID: TAutoIncField;
  22.     QryCompPers_LastName: TStringField;
  23.     QryCompPers_FirstName: TStringField;
  24.     QryCompPers_Remarks: TMemoField;
  25.     QryCompPers_Birthday: TDateTimeField;
  26.     QryCompPers_IsFemale: TBooleanField;
  27.     EditLookup: TEdit;
  28.     Label1: TLabel;
  29.     Label2: TLabel;
  30.     BtnFindNext: TButton;
  31.     Label3: TLabel;
  32.     Label4: TLabel;
  33.     procedure BtnLookupClick(Sender: TObject);
  34.     procedure BtnFindFirstClick(Sender: TObject);
  35.     procedure FormCreate(Sender: TObject);
  36.     procedure BtnFindNextClick(Sender: TObject);
  37.   private
  38.     { Private declarations }
  39.   public
  40.     { Public declarations }
  41.   end;
  42.  
  43. var
  44.   FormFastFind: TFormFastFind;
  45.  
  46. implementation
  47. uses
  48.   DAO, OleAuto;
  49.  
  50. {$R *.DFM}
  51.  
  52.  
  53. procedure TFormFastFind.BtnLookupClick(Sender: TObject);
  54.   var
  55.     fName: Variant;
  56.   begin
  57.     with QryComp do begin
  58.       fName:= Lookup('Pers_LastName', EditLookup.Text,'Pers_FirstName');
  59.       if VarType(fName) = varString then begin
  60.         ShowMessage( 'Firstname of ' + EditLookup.Text + ' is <' + fName + '>' );
  61.       end else begin
  62.         ShowMessage( 'No match found.' );
  63.       end;
  64.     end;
  65.   end {BtnLookupClick};
  66.  
  67.  
  68. procedure TFormFastFind.BtnFindFirstClick(Sender: TObject);
  69.   { This procedure uses the late-bound OLE-Automation mechanism of Delphi to communicate
  70.     with the DAO-recordset. }
  71.   var
  72.     rs: Variant;
  73.   begin
  74.     with QryComp do begin
  75.       if Active then begin
  76.           { get the DAO recordset handle into the variant <rs> }
  77.         rs:= DAORecordset(Handle).AsVariant;
  78.           { perform a DAO FindFirst }
  79.         rs.FindFirst( EditFindText.Text );
  80.           { check of sth. found }
  81.         if rs.NoMatch then ShowMessage( 'No match found.' );
  82.           { resynchronize the dataset }
  83.         Resync( [] );
  84.       end;
  85.     end;
  86.   end {BtnFindFirstClick};
  87.  
  88.  
  89. procedure TFormFastFind.BtnFindNextClick(Sender: TObject);
  90.   { This procedure uses the early bound OLE-Automation objects defined by Opus in
  91.     DAO unit to communicate with the DAO-recordset. }
  92.   var
  93.     rs: DAORecordset;
  94.   begin
  95.     with QryComp do begin
  96.       if Active then begin
  97.           { get the DAO recordset handle into the DAORecordset pointer <rs> }
  98.         rs:= DAORecordset( Handle );
  99.           { perform a DAO FindNext }
  100.         rs.FindNext( EditFindText.Text );
  101.           { check if sth. found }
  102.         if rs.NoMatch then ShowMessage( 'No match found.' );
  103.           { resynchronize the dataset }
  104.         Resync( [] );
  105.  
  106.         { Don't free this recordset, because it is still used by the TQuery.
  107.           If you had used a clone, you would have needed to free it here.
  108.           Example:
  109.  
  110.             rs:= DAORecordset( Handle ).Clone;
  111.             with rs do try
  112.               ....
  113.             finally Free end;
  114.         }
  115.  
  116.       end;
  117.     end {with QryComp};
  118.   end {BtnFindNextClick};
  119.  
  120.  
  121. procedure TFormFastFind.FormCreate(Sender: TObject);
  122.   begin
  123.     QryComp.Open;
  124.   end {FormCreate};
  125.  
  126.  
  127. end.
  128.