modified 'search by grid column' function, modified 'grid selection' function

This commit is contained in:
rickarof 2018-08-22 12:03:30 -03:00
parent abc715fd8d
commit f1d709a5a3
9 changed files with 87 additions and 23 deletions

View File

@ -55,14 +55,26 @@ procedure TFormGrid.btEscolherClick(Sender: TObject);
var var
wObj: TObject; wObj: TObject;
FormCidade: TFormCidade; FormCidade: TFormCidade;
wCod: integer;
begin begin
try try
if FClass = TCidade then if FClass = TCidade then
Dado1.Dado := StringGrid1.Row; begin
wCod := strtoint(StringGrid1.Cells[0, StringGrid1.Row]);
Dado1.Dado := FLista.getIndexByCod(wCod);
end
else
if FClass = TEstado then if FClass = TEstado then
Dado2.Dado := StringGrid1.Row; begin
wCod := strtoint(StringGrid1.Cells[0, StringGrid1.Row]);
Dado2.Dado := FLista.getIndexByCod(wCod);
end
else
if FClass = TPais then if FClass = TPais then
Dado3.Dado := StringGrid1.Row; begin
wCod := strtoint(StringGrid1.Cells[0, StringGrid1.Row]);
Dado3.Dado := Flista.getIndexByCod(wCod);
end;
finally finally
Self.Free; Self.Free;
end; end;
@ -161,29 +173,24 @@ begin
begin begin
wObj := FLista.getObjectByIndex(wCont); wObj := FLista.getObjectByIndex(wCont);
if wObj.ClassType = TCidade then if wObj.ClassType = TCidade then
begin
with wObj as TCidade do with wObj as TCidade do
begin begin
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;
StringGrid1.Cells[3, wCont] := wUF; StringGrid1.Cells[3, wCont] := wUF;
end;
end end
else else
if wObj.ClassType = TEstado then if wObj.ClassType = TEstado then
begin
with wObj as TEstado do with wObj as TEstado do
begin begin
StringGrid1.Cells[0, wcont] := inttostr(wCod); StringGrid1.Cells[0, wcont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wEstado; StringGrid1.Cells[1, wCont] := wEstado;
StringGrid1.Cells[2, wCont] := wPais; StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := inttostr(wAliquota); StringGrid1.Cells[3, wCont] := inttostr(wAliquota);
end;
end end
else else
if wObj.ClassType = TPais then if wObj.ClassType = TPais then
begin
with wObj as TPais do with wObj as TPais do
begin begin
StringGrid1.Cells[0, wcont] := inttostr(wCod); StringGrid1.Cells[0, wcont] := inttostr(wCod);
@ -192,7 +199,6 @@ begin
StringGrid1.Cells[3, wCont] := inttostr(wCodFed); StringGrid1.Cells[3, wCont] := inttostr(wCodFed);
end; end;
end; end;
end;
end end
else else
begin begin
@ -236,12 +242,20 @@ begin
else else
if wObj.ClassType = TPais then if wObj.ClassType = TPais then
begin begin
with wObj as TPais do
if (wCol =0) and (ContainsText (inttostr(wCod), edKeyPress.Text)) then
wLista.Inserir(wObj, TPais)
else
if (wCol =1) and (ContainsText(wPais, edKeypress.Text)) then
wLista.Inserir(wObj, TPais)
else
if (wCol =2) and (ContainsText(wNacionalidade, edKeyPress.Text)) then
wLista.Inserir(wObj, TPais)
else
if (wCol =3) and (ContainsText(inttostr(wCodFed), edKeyPress.Text)) then
wLista.Inserir(wObj, TPais);
end; end;
end; end;
if wLista.Count > 0 then if wLista.Count > 0 then
begin begin
limpaGrid(); limpaGrid();
@ -250,15 +264,32 @@ begin
begin begin
wObj := wLista.getObjectByIndex(wCont); wObj := wLista.getObjectByIndex(wCont);
if wObj.ClassType = TCidade then if wObj.ClassType = TCidade then
begin
with wObj as TCidade do with wObj as TCidade do
begin begin
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;
StringGrid1.Cells[3, wCont] := wUF; StringGrid1.Cells[3, wCont] := wUF;
end
else
if wObj.ClassType = TEstado then
with wObj as TEstado do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wEstado;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := inttostr(wAliquota);
end
else
if wObj.ClassType = TPais then
with wObj as TPais do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wPais;
StringGrid1.Cells[2, wCont] := wNacionalidade;
StringGrid1.Cells[3, wCont] := inttostr(wCodFed);
end; end;
end;
end; end;
end; end;

View File

@ -19,14 +19,47 @@ public
function getObjectByIndex(Index: integer): TObject; function getObjectByIndex(Index: integer): TObject;
function getObjectList: TObjectList; function getObjectList: TObjectList;
function getIndexOfObj(wObj: TObject): integer; function getIndexOfObj(wObj: TObject): integer;
function getIndexByCod(Cod: integer): integer;
end; end;
implementation implementation
uses UnitFormCidade, UnitFormEstado, UnitFormPais;
constructor TLista.Create; constructor TLista.Create;
begin begin
FLista := TObjectList.Create; FLista := TObjectList.Create;
end; end;
function TLista.getIndexByCod(Cod: Integer): integer;
var
wCont: integer;
wObj: TObject;
begin
for wCont := 0 to FLista.Count-1 do
begin
wObj := FLista.Items[wCont];
if wObj.ClassType = TCidade then
begin
with wObj as TCidade do
if wCod = Cod then
Result := FLista.IndexOf(wObj);
end
else
if wObj.ClassType = TEstado then
begin
with wObj as TEstado do
if wCod = Cod then
Result := FLista.IndexOf(wObj);
end
else
if wObj.ClassType = TPais then
begin
with wObj as TPais do
if wCod = Cod then
Result := FLista.IndexOf(wObj);
end;
end;
end;
function TLista.getObjectByIndex(Index: Integer): TObject; // retorna um objeto de acordo com o index passado por parametro function TLista.getObjectByIndex(Index: Integer): TObject; // retorna um objeto de acordo com o index passado por parametro
var var
wObj: TObject; wObj: TObject;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.