modified 'search by name' function

This commit is contained in:
rickarof 2018-08-21 12:41:06 -03:00
parent 9131da2ccf
commit 79d111221f
7 changed files with 66 additions and 20 deletions

View File

@ -15,6 +15,7 @@ object FormGrid: TFormGrid
OldCreateOrder = False OldCreateOrder = False
Visible = True Visible = True
OnClose = FormClose OnClose = FormClose
OnCreate = FormCreate
PixelsPerInch = 96 PixelsPerInch = 96
TextHeight = 13 TextHeight = 13
object Label1: TLabel object Label1: TLabel

View File

@ -5,7 +5,7 @@ interface
uses uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, UnitLista, UnitFormEstado, UnitFormPais, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, UnitLista, UnitFormEstado, UnitFormPais,
Vcl.ToolWin, Vcl.ComCtrls, Vcl.StdCtrls, UnitDados; Vcl.ToolWin, Vcl.ComCtrls, Vcl.StdCtrls, UnitDados, System.StrUtils;
type type
TFormGrid = class(TForm) TFormGrid = class(TForm)
@ -20,6 +20,8 @@ type
procedure btExcluirClick(Sender: TObject); procedure btExcluirClick(Sender: TObject);
procedure btEscolherClick(Sender: TObject); procedure btEscolherClick(Sender: TObject);
procedure edPesquisaChange(Sender: TObject); procedure edPesquisaChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure testeStringGrid(Lista: TLista; Classe: TClass);
private private
{ Private declarations } { Private declarations }
palavra: string; palavra: string;
@ -31,10 +33,33 @@ var
FormGrid: TFormGrid; FormGrid: TFormGrid;
FClass: TClass; FClass: TClass;
FLista: TLista; FLista: TLista;
checkList: boolean;
implementation implementation
{$R *.dfm} {$R *.dfm}
uses UnitFormCidade; uses UnitFormCidade;
procedure TFormGrid.testeStringGrid(Lista: TLista; Classe: TClass);
var
wCont: Integer;
wObj: TObject;
begin
for wCont := 0 to Lista.Count-1 do
begin
wObj := Lista.getObjectByIndex(wCont);
if Classe = TCidade then
begin
with wObj as TCidade do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wCidade;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := wUF;
end;
end;
end;
end;
procedure TFormGrid.btEscolherClick(Sender: TObject); procedure TFormGrid.btEscolherClick(Sender: TObject);
var var
wObj: TObject; wObj: TObject;
@ -70,15 +95,15 @@ end;
procedure TFormGrid.edPesquisaChange(Sender: TObject); procedure TFormGrid.edPesquisaChange(Sender: TObject);
var var
wString: string;
wCont: integer; wCont: integer;
wObj: TObject; wObj: TObject;
wCont2: integer; wCont2: integer;
wCheckString: string; wCheckString: string;
wLista: TLista; wLista: TLista;
wObj2: TObject;
I: Integer;
begin begin
palavra := edPesquisa.Text; palavra := edPesquisa.Text;
wCheckString := '';
wLista := TLista.Create; wLista := TLista.Create;
for wCont := 0 to FLista.Count-1 do for wCont := 0 to FLista.Count-1 do
begin begin
@ -87,20 +112,28 @@ begin
begin begin
with wObj as TCidade do with wObj as TCidade do
begin begin
for wCont2 := 1 to wCidade.Length do if ContainsText(wCidade, palavra) then
begin begin
wCheckString := wCheckString + Copy(wCidade, wCont2, 1); ShowMessage('Resultado containstext:'+booltostr(ContainsText(wCidade, palavra)));
if wCheckString = palavra then wLista.Inserir(wObj, TCidade);
begin end;
ShowMessage(wCheckString);
wLista.Inserir(wObj, TCidade);
exit;
end;
end;
end; end;
end; end;
end; end;
FormGrid.geraGrid(wLista, TCidade);
ShowMessage('lista count:'+inttostr(wLista.Count));
for I := 0 to wLista.Count-1 do
begin
wObj2 := wLista.getObjectByIndex(I);
with wObj2 as TCidade do
begin
ShowMessage(wCidade);
end;
end;
if wLista.Count > 0 then
begin
FormGrid.testeStringGrid(wLista, TCidade);
end;
end; end;
@ -109,22 +142,34 @@ begin
Action := caFree; Action := caFree;
end; end;
procedure TFormGrid.FormCreate(Sender: TObject);
begin
checkList := true;
end;
procedure TFormGrid.geraGrid(wLista: TLista; wClass: TClass); procedure TFormGrid.geraGrid(wLista: TLista; wClass: TClass);
var var
wCont: integer; wCont: integer;
wObj: TObject; wObj: TObject;
begin begin
FClass := wClass; if checkList = true then
FLista := wLista; begin
wObj := FClass.Create; FLista := wLista;
StringGrid1.RowCount := FLista.Count; FClass := wClass;
for wCont := 0 to FLista.Count-1 do checkList := false;
end;
wObj := wClass.Create;
ShowMessage('wLista count:'+inttostr(wLista.Count));
//StringGrid1.RowCount := wLista.Count;
for wCont := 0 to wLista.Count-1 do
begin begin
wObj := FLista.getObjectByIndex(wCont); wObj := wLista.getObjectByIndex(wCont);
// fazer uma condição para cada tipo de Classe existente // fazer uma condição para cada tipo de Classe existente
if wObj.ClassType = TCidade then if wObj.ClassType = TCidade then
with wObj as TCidade do with wObj as TCidade do
begin begin
ShowMessage('cod:'+inttostr(wCod));
ShowMessage('testestring:'+wCidade);
StringGrid1.Cells[0, wCont] := inttostr(wCod); StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wCidade; StringGrid1.Cells[1, wCont] := wCidade;
StringGrid1.Cells[2, wCont] := wPais; StringGrid1.Cells[2, wCont] := wPais;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.