home *** CD-ROM | disk | FTP | other *** search
- unit DemoFastFind;
-
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, DBCtrls, Mask, ExtCtrls, DB, DBTables, DBCGrids;
-
- type
- TFormFastFind = class(TForm)
- QryComp: TQuery;
- SrcComp: TDataSource;
- DBNavigator1: TDBNavigator;
- DBCtrlGrid1: TDBCtrlGrid;
- Pers_LastName: TDBEdit;
- Pers_FirstName: TDBEdit;
- Pers_Birthday: TDBText;
- Pers_Remarks: TDBMemo;
- BtnLookup: TButton;
- BtnFindFirst: TButton;
- EditFindText: TEdit;
- QryCompPers_ID: TAutoIncField;
- QryCompPers_LastName: TStringField;
- QryCompPers_FirstName: TStringField;
- QryCompPers_Remarks: TMemoField;
- QryCompPers_Birthday: TDateTimeField;
- QryCompPers_IsFemale: TBooleanField;
- EditLookup: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- BtnFindNext: TButton;
- Label3: TLabel;
- Label4: TLabel;
- procedure BtnLookupClick(Sender: TObject);
- procedure BtnFindFirstClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure BtnFindNextClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- FormFastFind: TFormFastFind;
-
- implementation
- uses
- DAO, OleAuto;
-
- {$R *.DFM}
-
-
- procedure TFormFastFind.BtnLookupClick(Sender: TObject);
- var
- fName: Variant;
- begin
- with QryComp do begin
- fName:= Lookup('Pers_LastName', EditLookup.Text,'Pers_FirstName');
- if VarType(fName) = varString then begin
- ShowMessage( 'Firstname of ' + EditLookup.Text + ' is <' + fName + '>' );
- end else begin
- ShowMessage( 'No match found.' );
- end;
- end;
- end {BtnLookupClick};
-
-
- procedure TFormFastFind.BtnFindFirstClick(Sender: TObject);
- { This procedure uses the late-bound OLE-Automation mechanism of Delphi to communicate
- with the DAO-recordset. }
- var
- rs: Variant;
- begin
- with QryComp do begin
- if Active then begin
- { get the DAO recordset handle into the variant <rs> }
- rs:= DAORecordset(Handle).AsVariant;
- { perform a DAO FindFirst }
- rs.FindFirst( EditFindText.Text );
- { check of sth. found }
- if rs.NoMatch then ShowMessage( 'No match found.' );
- { resynchronize the dataset }
- Resync( [] );
- end;
- end;
- end {BtnFindFirstClick};
-
-
- procedure TFormFastFind.BtnFindNextClick(Sender: TObject);
- { This procedure uses the early bound OLE-Automation objects defined by Opus in
- DAO unit to communicate with the DAO-recordset. }
- var
- rs: DAORecordset;
- begin
- with QryComp do begin
- if Active then begin
- { get the DAO recordset handle into the DAORecordset pointer <rs> }
- rs:= DAORecordset( Handle );
- { perform a DAO FindNext }
- rs.FindNext( EditFindText.Text );
- { check if sth. found }
- if rs.NoMatch then ShowMessage( 'No match found.' );
- { resynchronize the dataset }
- Resync( [] );
-
- { Don't free this recordset, because it is still used by the TQuery.
- If you had used a clone, you would have needed to free it here.
- Example:
-
- rs:= DAORecordset( Handle ).Clone;
- with rs do try
- ....
- finally Free end;
- }
-
- end;
- end {with QryComp};
- end {BtnFindNextClick};
-
-
- procedure TFormFastFind.FormCreate(Sender: TObject);
- begin
- QryComp.Open;
- end {FormCreate};
-
-
- end.
-