added 'search by name' function

This commit is contained in:
rickarof 2018-08-21 11:04:52 -03:00
parent fe90e396e3
commit 9131da2ccf
7 changed files with 62 additions and 6 deletions

View File

@ -1,8 +1,8 @@
object FormGrid: TFormGrid object FormGrid: TFormGrid
Left = 0 Left = 0
Top = 0 Top = 0
Width = 365 Width = 448
Height = 340 Height = 418
AutoScroll = True AutoScroll = True
Caption = 'FormGrid' Caption = 'FormGrid'
Color = clBtnFace Color = clBtnFace
@ -17,6 +17,13 @@ object FormGrid: TFormGrid
OnClose = FormClose OnClose = FormClose
PixelsPerInch = 96 PixelsPerInch = 96
TextHeight = 13 TextHeight = 13
object Label1: TLabel
Left = 48
Top = 228
Width = 46
Height = 13
Caption = 'Pesquisa:'
end
object StringGrid1: TStringGrid object StringGrid1: TStringGrid
Left = 8 Left = 8
Top = 35 Top = 35
@ -33,16 +40,17 @@ object FormGrid: TFormGrid
object ToolBar1: TToolBar object ToolBar1: TToolBar
Left = 0 Left = 0
Top = 0 Top = 0
Width = 349 Width = 432
Height = 29 Height = 29
ButtonHeight = 25 ButtonHeight = 21
Caption = 'ToolBar1' Caption = 'ToolBar1'
TabOrder = 1 TabOrder = 1
ExplicitWidth = 349
object btExcluir: TButton object btExcluir: TButton
Left = 0 Left = 0
Top = 0 Top = 0
Width = 70 Width = 70
Height = 25 Height = 21
Caption = 'Excluir' Caption = 'Excluir'
TabOrder = 0 TabOrder = 0
OnClick = btExcluirClick OnClick = btExcluirClick
@ -51,11 +59,19 @@ object FormGrid: TFormGrid
Left = 70 Left = 70
Top = 0 Top = 0
Width = 70 Width = 70
Height = 25 Height = 21
Caption = 'Escolher' Caption = 'Escolher'
Default = True Default = True
TabOrder = 1 TabOrder = 1
OnClick = btEscolherClick OnClick = btEscolherClick
end end
end end
object edPesquisa: TEdit
Left = 100
Top = 225
Width = 121
Height = 21
TabOrder = 2
OnChange = edPesquisaChange
end
end end

View File

@ -13,12 +13,16 @@ type
ToolBar1: TToolBar; ToolBar1: TToolBar;
btExcluir: TButton; btExcluir: TButton;
btEscolher: TButton; btEscolher: TButton;
edPesquisa: TEdit;
Label1: TLabel;
procedure geraGrid(wLista: TLista; wClass: TClass); procedure geraGrid(wLista: TLista; wClass: TClass);
procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btExcluirClick(Sender: TObject); procedure btExcluirClick(Sender: TObject);
procedure btEscolherClick(Sender: TObject); procedure btEscolherClick(Sender: TObject);
procedure edPesquisaChange(Sender: TObject);
private private
{ Private declarations } { Private declarations }
palavra: string;
public public
{ Public declarations } { Public declarations }
end; end;
@ -64,6 +68,42 @@ begin
end; end;
procedure TFormGrid.edPesquisaChange(Sender: TObject);
var
wString: string;
wCont: integer;
wObj: TObject;
wCont2: integer;
wCheckString: string;
wLista: TLista;
begin
palavra := edPesquisa.Text;
wCheckString := '';
wLista := TLista.Create;
for wCont := 0 to FLista.Count-1 do
begin
wObj := FLista.getObjectByIndex(wCont);
if FClass = TCidade then
begin
with wObj as TCidade do
begin
for wCont2 := 1 to wCidade.Length do
begin
wCheckString := wCheckString + Copy(wCidade, wCont2, 1);
if wCheckString = palavra then
begin
ShowMessage(wCheckString);
wLista.Inserir(wObj, TCidade);
exit;
end;
end;
end;
end;
end;
FormGrid.geraGrid(wLista, TCidade);
end;
procedure TFormGrid.FormClose(Sender: TObject; var Action: TCloseAction); procedure TFormGrid.FormClose(Sender: TObject; var Action: TCloseAction);
begin begin
Action := caFree; Action := caFree;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.