Marco Web Center |
|
Chapter 13 - Project Search |
Project Structure |
Search.dpr |
program Search; uses Forms, SearchF in 'SearchF.pas' {SearchForm}; {$R *.RES} begin Application.CreateForm(TSearchForm, SearchForm); Application.Run; end. |
SearchF.pas |
unit SearchF; interface uses SysUtils, Windows, Messages, Classes, Graphics, Controls, Variants, StdCtrls, Forms, DBCtrls, DB, Buttons, DBTables, Mask, ExtCtrls, Dialogs, DBActns, ActnList, ImgList, ComCtrls, ToolWin; type TSearchForm = class(TForm) DataSource1: TDataSource; Table1: TTable; Table1Salary: TFloatField; Table1EmpNo: TIntegerField; Table1LastName: TStringField; Table1FirstName: TStringField; Table1PhoneExt: TStringField; Table1HireDate: TDateTimeField; ActionList1: TActionList; ToolBar1: TToolBar; ToolButton1: TToolButton; ToolButton2: TToolButton; ToolButton3: TToolButton; ToolButton4: TToolButton; ImageList1: TImageList; DataSetFirst1: TDataSetFirst; DataSetLast1: TDataSetLast; DataSetNext1: TDataSetNext; DataSetPrior1: TDataSetPrior; EditName: TEdit; ToolButton5: TToolButton; ToolButton6: TToolButton; ToolButton7: TToolButton; ActionGoto: TAction; ActionGoNear: TAction; ScrollBox: TScrollBox; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; EditEmpNo: TDBEdit; EditLastName: TDBEdit; EditFirstName: TDBEdit; EditPhoneExt: TDBEdit; EditHireDate: TDBEdit; EditSalary: TDBEdit; ActionMulti: TAction; ToolButton8: TToolButton; procedure FormCreate(Sender: TObject); procedure ActionGoNearExecute(Sender: TObject); procedure ActionGotoExecute(Sender: TObject); procedure ActionGotoUpdate(Sender: TObject); procedure ActionGoNearUpdate(Sender: TObject); procedure ActionMultiExecute(Sender: TObject); private { private declarations } public { public declarations } end; var SearchForm: TSearchForm; implementation {$R *.DFM} procedure TSearchForm.FormCreate(Sender: TObject); begin Table1.First; end; procedure TSearchForm.ActionGoNearExecute(Sender: TObject); begin if not Table1.Locate ('LastName', EditName.Text, [loPartialKey]) then MessageDlg ('No name begins with "' + EditName.Text + '"', mtError, [mbOk], 0); end; procedure TSearchForm.ActionGotoExecute(Sender: TObject); begin if not Table1.Locate ('LastName', EditName.Text, []) then MessageDlg ('"' + EditName.Text + '" not found', mtError, [mbOk], 0); end; procedure TSearchForm.ActionGotoUpdate(Sender: TObject); begin ActionGoto.Enabled := EditName.Text <> ''; end; procedure TSearchForm.ActionGoNearUpdate(Sender: TObject); begin ActionGoNear.Enabled := EditName.Text <> ''; end; procedure TSearchForm.ActionMultiExecute(Sender: TObject); begin if not Table1.Locate ('LastName;FirstName', VarArrayOf (['Cook', 'Kevin']), []) then MessageDlg ('Not found', mtError, [mbOk], 0); end; end. |
SearchF.dfm |
object SearchForm: TSearchForm Left = 300 Top = 214 Width = 403 Height = 204 Caption = 'Table Search' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clBlack Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = True Position = poScreenCenter OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object ToolBar1: TToolBar Left = 0 Top = 0 Width = 395 Height = 27 Caption = 'ToolBar1' Customizable = False EdgeBorders = [ebTop, ebBottom] Flat = True Images = ImageList1 ParentShowHint = False ShowHint = True TabOrder = 0 object ToolButton1: TToolButton Left = 0 Top = 0 Action = DataSetFirst1 end object ToolButton2: TToolButton Left = 23 Top = 0 Action = DataSetPrior1 end object ToolButton3: TToolButton Left = 46 Top = 0 Action = DataSetNext1 end object ToolButton4: TToolButton Left = 69 Top = 0 Action = DataSetLast1 end object ToolButton5: TToolButton Left = 92 Top = 0 Width = 8 Caption = 'ToolButton5' ImageIndex = 3 Style = tbsSeparator end object EditName: TEdit Left = 100 Top = 0 Width = 137 Height = 22 Color = clWindow Font.Charset = DEFAULT_CHARSET Font.Color = clBlack Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] ParentFont = False TabOrder = 0 Text = 'Williams' end object ToolButton7: TToolButton Left = 237 Top = 0 Action = ActionGoto end object ToolButton6: TToolButton Left = 260 Top = 0 Action = ActionGoNear end object ToolButton8: TToolButton Left = 283 Top = 0 Action = ActionMulti end end object ScrollBox: TScrollBox Left = 0 Top = 27 Width = 395 Height = 150 HorzScrollBar.Margin = 6 VertScrollBar.Margin = 6 Align = alClient BorderStyle = bsNone TabOrder = 1 object Label1: TLabel Left = 230 Top = 17 Width = 60 Height = 13 Alignment = taRightJustify AutoSize = False Caption = '&Emp No' FocusControl = EditEmpNo end object Label2: TLabel Left = 14 Top = 15 Width = 60 Height = 13 Alignment = taRightJustify AutoSize = False Caption = '&Last Name' FocusControl = EditLastName end object Label3: TLabel Left = 14 Top = 36 Width = 60 Height = 13 Alignment = taRightJustify AutoSize = False Caption = '&First Name' FocusControl = EditFirstName end object Label4: TLabel Left = 14 Top = 58 Width = 60 Height = 13 Alignment = taRightJustify AutoSize = False Caption = '&Phone Ext' FocusControl = EditPhoneExt end object Label5: TLabel Left = 230 Top = 39 Width = 60 Height = 13 Alignment = taRightJustify AutoSize = False Caption = '&Hire Date' FocusControl = EditHireDate end object Label6: TLabel Left = 14 Top = 79 Width = 60 Height = 13 Alignment = taRightJustify AutoSize = False Caption = '&Salary' FocusControl = EditSalary end object EditEmpNo: TDBEdit Left = 296 Top = 14 Width = 57 Height = 21 Color = clWindow DataField = 'EmpNo' DataSource = DataSource1 TabOrder = 0 end object EditLastName: TDBEdit Left = 80 Top = 12 Width = 97 Height = 21 Color = clWindow DataField = 'LastName' DataSource = DataSource1 TabOrder = 1 end object EditFirstName: TDBEdit Left = 80 Top = 33 Width = 97 Height = 21 Color = clWindow DataField = 'FirstName' DataSource = DataSource1 TabOrder = 2 end object EditPhoneExt: TDBEdit Left = 80 Top = 55 Width = 97 Height = 21 Color = clWindow DataField = 'PhoneExt' DataSource = DataSource1 TabOrder = 3 end object EditHireDate: TDBEdit Left = 296 Top = 36 Width = 57 Height = 21 Color = clWindow DataField = 'HireDate' DataSource = DataSource1 TabOrder = 4 end object EditSalary: TDBEdit Left = 80 Top = 76 Width = 97 Height = 21 Color = clWindow DataField = 'Salary' DataSource = DataSource1 TabOrder = 5 end end object DataSource1: TDataSource AutoEdit = False DataSet = Table1 Left = 279 Top = 109 end object Table1: TTable Active = True DatabaseName = 'DBDEMOS' IndexFieldNames = 'LastName;FirstName' TableName = 'employee.db' Left = 332 Top = 109 object Table1Salary: TFloatField FieldName = 'Salary' end object Table1EmpNo: TIntegerField FieldName = 'EmpNo' end object Table1LastName: TStringField FieldName = 'LastName' end object Table1FirstName: TStringField FieldName = 'FirstName' Size = 15 end object Table1PhoneExt: TStringField FieldName = 'PhoneExt' Size = 4 end object Table1HireDate: TDateTimeField FieldName = 'HireDate' end end object ActionList1: TActionList Images = ImageList1 Left = 214 Top = 111 object DataSetFirst1: TDataSetFirst Category = 'Dataset' Caption = '&First' Hint = 'First' ImageIndex = 0 end object DataSetLast1: TDataSetLast Category = 'Dataset' Caption = '&Last' Hint = 'Last' ImageIndex = 1 end object DataSetNext1: TDataSetNext Category = 'Dataset' Caption = '&Next' Hint = 'Next' ImageIndex = 2 end object DataSetPrior1: TDataSetPrior Category = 'Dataset' Caption = '&Prior' Hint = 'Prior' ImageIndex = 3 end object ActionGoto: TAction Caption = '&Goto' Hint = 'Goto' ImageIndex = 4 OnExecute = ActionGotoExecute OnUpdate = ActionGotoUpdate end object ActionGoNear: TAction Caption = 'Go &Near' Hint = 'Go Near' ImageIndex = 5 OnExecute = ActionGoNearExecute OnUpdate = ActionGoNearUpdate end object ActionMulti: TAction Caption = 'Multi Field' ImageIndex = 6 OnExecute = ActionMultiExecute end end object ImageList1: TImageList Left = 24 Top = 128 Bitmap = { 494C010107000900040010001000FFFFFFFFFF00FFFFFFFFFFFFFFFF424D3600 0000000000003600000028000000400000003000000001001000000000000018 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000FF7F0000 FF7F0000000000000000FF7FFF7FFF7F00000000000000000000000000000000 000000000000000000000000000000000000FF0300000000E07FFF7FE07FFF7F E07F000000000000000000000000000000000000E07F00000000000000000000 000000000000000000000000000000000000000000000000FF7F0000FF7F0000 FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000 000000000000000000000000000000000000FF030000E07FFF7FE07FFF7F0000 000000000000000000000000000000000000000000000000FF0300000000E07F FF7FE07FFF7FE07F000000000000000000000000FF7F0000FF7F0000FF7F0000 FF7F000000000000000000000000FF7F00000000000000000000000000000000 000000000000000000000000000000000000FF030000FF7FE07FFF7FE07FFF7F E07FFF7F0000000000000000000000000000000000000000FF030000E07FFF7F E07FFF7F00000000000000000000000000000000FF7F0000FF7F0000FF7F0000 FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000 000000000000000000000000000000000000FF030000E07FFF7FE07FFF7F0000 000000000000000000000000000000000000000000000000FF030000FF7FE07F FF7FE07FFF7FE07FFF7F00000000000000000000FF7F0000FF7F0000FF7F0000 FF7F000000000000000000000000FF7F00000000000000000000000000000000 000000000000000000000000000000000000FF030000FF7FE07FFF7FE07FFF7F E07FFF7FE07FFF7FE07F00000000007C007C000000000000FF030000E07FFF7F E07FFF7F00000000000000000000000000000000FF7F0000FF7F0000FF7F0000 FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000 000000000000000000000000000000000000FF030000E07FFF7F000000000000 0000000000000000000000000000007C007C000000000000FF030000FF7FE07F FF7FE07FFF7FE07FFF7FE07FFF7FE07F00000000FF7F0000FF7F0000FF7F0000 FF7F000000000000FF7FFF7FFF7FFF7F00000000000000000000000000000000 000000000000000000000000000000000000000000000000E07FFF7FE07F0000 000000000000000000000000000000000000000000000000FF030000E07FFF7F 0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000 FF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000E07F FF7FE07F00000000000000000000000000000000FF7F0000FF7F0000FF7F0000 FF7F00000000FF7FFF7F0000FF7F000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000 FF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000FF7F0000FF7F000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000FF7F00000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000104200000000 0000000000000000104200000000000000000000000000000000104200000000 0000000000000000104200000000000000000000000000000000000000001042 0000000000000000000000000000000000000000000000000000000000000000 0000000010420000000000000000000000000000000000000000104200000000 0000000010420000000000000000000000000000000000000000000000001042 0000000000000000104200000000000000000000000000000000000000000000 0000104200000000000000000000000000000000000000000000000000000000 1042000000000000000000000000000000000000000000000000104200000000 1042000000000000000000000000000000000000000000000000000000000000 0000104200000000104200000000000000000000000000000000000000000000 0000000000001042000000000000000000000000000000000000000010420000 0000000000000000000000000000000000000000000000000000104210420000 0000000000000000000000000000000000000000000000000000000000000000 0000000000001042104200000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000104200000000 1042000000000000000000000000000000000000000000000000000000000000 0000104200000000104200000000000000000000000000000000000000000000 0000000000001042000000000000000000000000000000000000000010420000 0000000000000000000000000000000000000000000000000000104200000000 0000000010420000000000000000000000000000000000000000000000001042 0000000000000000104200000000000000000000000000000000000000000000 0000104200000000000000000000000000000000000000000000000000000000 1042000000000000000000000000000000000000000000000000104200000000 0000000000000000104200000000000000000000000000000000104200000000 0000000000000000104200000000000000000000000000000000000000001042 0000000000000000000000000000000000000000000000000000000000000000 0000000010420000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000424D3E000000000000003E000000 2800000040000000300000000100010000000000800100000000000000000000 000000000000000000000000FFFFFF0000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000FFFFFFFFFC000000FFF8FFFFF0000000 20F81FFFC0000000007F041F00000000007C000F00000000003C000F00000000 000F0007000000000004000100000000000C00000000000001FF000100000000 E3FC003F00010000FFFCFC7F00030000FFFFFFFF00070000FFF8FFFF001F0000 FFF8FFFF007F0000FFFFFFFF01FF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE7E7E7E7F9FFFF9F E787E1E7F87FFE1FE607E067F81FF81FE007E007F80FF01FE607E067F81FF81F E787E1E7F87FFE1FE7E7E7E7F9FFFF9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} end end |