diff --git a/UnitFormGrid.pas b/UnitFormGrid.pas index bbbe092..5d10e09 100644 --- a/UnitFormGrid.pas +++ b/UnitFormGrid.pas @@ -55,14 +55,26 @@ procedure TFormGrid.btEscolherClick(Sender: TObject); var wObj: TObject; FormCidade: TFormCidade; + wCod: integer; begin try if FClass = TCidade then - Dado1.Dado := StringGrid1.Row; - if FClass = TEstado then - Dado2.Dado := StringGrid1.Row; - if FClass = TPais then - Dado3.Dado := StringGrid1.Row; + begin + wCod := strtoint(StringGrid1.Cells[0, StringGrid1.Row]); + Dado1.Dado := FLista.getIndexByCod(wCod); + end + else + if FClass = TEstado then + begin + wCod := strtoint(StringGrid1.Cells[0, StringGrid1.Row]); + Dado2.Dado := FLista.getIndexByCod(wCod); + end + else + if FClass = TPais then + begin + wCod := strtoint(StringGrid1.Cells[0, StringGrid1.Row]); + Dado3.Dado := Flista.getIndexByCod(wCod); + end; finally Self.Free; end; @@ -161,29 +173,24 @@ begin begin wObj := FLista.getObjectByIndex(wCont); if wObj.ClassType = 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 else if wObj.ClassType = TEstado then - begin 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; - end + end else if wObj.ClassType = TPais then - begin with wObj as TPais do begin StringGrid1.Cells[0, wcont] := inttostr(wCod); @@ -191,7 +198,6 @@ begin StringGrid1.Cells[2, wCont] := wNacionalidade; StringGrid1.Cells[3, wCont] := inttostr(wCodFed); end; - end; end; end else @@ -236,12 +242,20 @@ begin else if wObj.ClassType = TPais then 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; - if wLista.Count > 0 then begin limpaGrid(); @@ -250,15 +264,32 @@ begin begin wObj := wLista.getObjectByIndex(wCont); if wObj.ClassType = TCidade then - begin - with wObj as TCidade do + 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 + else + if wObj.ClassType = TEstado then + with wObj as TEstado do begin StringGrid1.Cells[0, wCont] := inttostr(wCod); - StringGrid1.Cells[1, wCont] := wCidade; + StringGrid1.Cells[1, wCont] := wEstado; StringGrid1.Cells[2, wCont] := wPais; - StringGrid1.Cells[3, wCont] := wUF; - end; - end; + 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; diff --git a/UnitLista.pas b/UnitLista.pas index 0de394e..7132ca0 100644 --- a/UnitLista.pas +++ b/UnitLista.pas @@ -19,14 +19,47 @@ public function getObjectByIndex(Index: integer): TObject; function getObjectList: TObjectList; function getIndexOfObj(wObj: TObject): integer; + function getIndexByCod(Cod: integer): integer; end; implementation + uses UnitFormCidade, UnitFormEstado, UnitFormPais; constructor TLista.Create; begin FLista := TObjectList.Create; 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 var wObj: TObject; diff --git a/Win32/Debug/Project1.exe b/Win32/Debug/Project1.exe index d3fda3d..84ea88f 100644 Binary files a/Win32/Debug/Project1.exe and b/Win32/Debug/Project1.exe differ diff --git a/Win32/Debug/UnitDados.dcu b/Win32/Debug/UnitDados.dcu index 3e7c101..ebc6fbb 100644 Binary files a/Win32/Debug/UnitDados.dcu and b/Win32/Debug/UnitDados.dcu differ diff --git a/Win32/Debug/UnitFormCidade.dcu b/Win32/Debug/UnitFormCidade.dcu index e77fd60..567926e 100644 Binary files a/Win32/Debug/UnitFormCidade.dcu and b/Win32/Debug/UnitFormCidade.dcu differ diff --git a/Win32/Debug/UnitFormEstado.dcu b/Win32/Debug/UnitFormEstado.dcu index 491fa2c..c1b3c25 100644 Binary files a/Win32/Debug/UnitFormEstado.dcu and b/Win32/Debug/UnitFormEstado.dcu differ diff --git a/Win32/Debug/UnitFormGrid.dcu b/Win32/Debug/UnitFormGrid.dcu index 92badcd..62b8f2c 100644 Binary files a/Win32/Debug/UnitFormGrid.dcu and b/Win32/Debug/UnitFormGrid.dcu differ diff --git a/Win32/Debug/UnitFormPais.dcu b/Win32/Debug/UnitFormPais.dcu index 937a08f..cc39002 100644 Binary files a/Win32/Debug/UnitFormPais.dcu and b/Win32/Debug/UnitFormPais.dcu differ diff --git a/Win32/Debug/UnitLista.dcu b/Win32/Debug/UnitLista.dcu index 81969fc..bccc412 100644 Binary files a/Win32/Debug/UnitLista.dcu and b/Win32/Debug/UnitLista.dcu differ