Модуль поиска по имени узла в компоненте выглядит следующим образом
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
unit uSearch3; interface uses System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client,uDBConnectionBPL,uSQLQueries,vcl.Dialogs; type TDMSearch = class(TDataModule) qSearch: TFDQuery; DataSource: TDataSource; procedure DataModuleCreate(Sender: TObject); procedure DataModuleDestroy(Sender: TObject); private FDBConnection:TDBConnectionBPL; FSQLQueries:TSQLQueries; { Private declarations } public procedure Search(Name:string); { Public declarations } end; var DMSearch: TDMSearch; implementation uses UTreeView; {%CLASSGROUP 'Vcl.Controls.TControl'} {$R *.dfm} procedure TDMSearch.DataModuleCreate(Sender: TObject); begin FDBConnection:=TDBConnectionBPL.Create(Self); //showmessage(FDBConnection.DBConnectionParams); qSearch.Connection:=FDBConnection.FDConnection; //TSQLQueries.Create(Self); end; procedure TDMSearch.DataModuleDestroy(Sender: TObject); begin FreeAndNil(FDBConnection); FreeAndNil(FSQLQueries); FreeAndNil(qSearch); FSQLQueries:=nil; end; procedure TDMSearch.Search(Name: string); begin if FSQLQueries=nil then FSQLQueries:=TSQLQueries.Create(Self); qSearch.SQL.Text:=FSQLQueries.Search.Text+'''%'+name+'%'''; //showmessage(FSQLQueries.Search.Text); //'SELECT name FROM treeview_db.tree where Name like '+'''%'+name+'%'''; // if qSearch.OpenOrExecute then qSearch.Close; qSearch.Open(); end; end. |
В главном модуле компонента
1 2 3 4 5 6 7 |
procedure TDBTreeView.Search(name: string); begin FDMSearch.Search(Name); FDataSource:=FDMSearch.DataSource; end; |
Непосредственно в программе, использующей компонент
1 2 3 4 5 6 7 8 9 |
procedure TMainForm.eSearchChange(Sender: TObject); begin if eSearch.Text='' then exit; DBTreeView1.Search(eSearch.text); DBGrid1.DataSource:=DBTreeView1.DataSource; end; |