mirror of
https://github.com/rickrd/crud-delphi.git
synced 2025-12-19 09:03:43 +01:00
modified 'search by name' function
This commit is contained in:
parent
9131da2ccf
commit
79d111221f
@ -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
|
||||||
|
|||||||
@ -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
|
|
||||||
begin
|
|
||||||
ShowMessage(wCheckString);
|
|
||||||
wLista.Inserir(wObj, TCidade);
|
wLista.Inserir(wObj, TCidade);
|
||||||
exit;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
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;
|
||||||
FormGrid.geraGrid(wLista, TCidade);
|
|
||||||
|
|
||||||
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;
|
|
||||||
wObj := FClass.Create;
|
|
||||||
StringGrid1.RowCount := FLista.Count;
|
|
||||||
for wCont := 0 to FLista.Count-1 do
|
|
||||||
begin
|
begin
|
||||||
wObj := FLista.getObjectByIndex(wCont);
|
FLista := wLista;
|
||||||
|
FClass := wClass;
|
||||||
|
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
|
||||||
|
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.
Loading…
Reference in New Issue
Block a user