unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls, jpeg;

type
  TForm3 = class(TForm)
    BitBtn1: TBitBtn;
    StringGrid1: TStringGrid;
    BitBtn2: TBitBtn;
    ComboBox1: TComboBox;
    Bevel1: TBevel;
    Bevel2: TBevel;
    Label1: TLabel;
    Image1: TImage;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure StringGrid1DblClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
  private
    { Private declarations }
    /////////////////////////

   //////////////////////////
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

uses
  Unit1,
  Unit4;

{$R *.dfm}

procedure TForm3.BitBtn1Click(Sender: TObject);
var
 RegN: integer;
 Reg: TPessoasReg;
begin
 RegN:=ComboBox1.ItemIndex;
 Unit4.LerArq (PesArq,RegN,Reg);
 Form1.EditCod.text:=vAgenda[Base.PsReg].Cod;
 Form1.EditCod.Text:=Reg.Cod;
 Form1.Edit1.Text:=Reg.Nome;
 Form1.Edit2.Text:=Reg.Telefone;
 Form1.Edit3.Text:=Reg.Bairro;
 Form1.Edit4.Text:=Reg.Numero_Res;
 Form1.Edit5.Text:=Reg.Numero_Ap;
 Form1.Edit6.Text:=Reg.Rua;
 Form1.Edit7.Text:=Reg.Referencia;
 Close;
end;

procedure TForm3.BitBtn2Click(Sender: TObject);
begin
 close;
end;

procedure TForm3.StringGrid1DblClick(Sender: TObject);
var
 RegN: integer;
 Reg: TPessoasReg;
begin
 RegN:=StringGrid1.row -1;;
 Unit4.LerArq (PesArq,RegN,Reg);
 Form1.Edit1.text:=vAgenda[Base.PsReg].Nome;
 Form1.Edit2.text:=vAgenda[Base.PsReg].Telefone;
 Form1.Edit3.text:=vAgenda[Base.PsReg].Bairro;
 Form1.Edit4.text:=vAgenda[Base.PsReg].Numero_Res;
 Form1.Edit5.text:=vAgenda[Base.PsReg].Numero_Ap;
 Form1.Edit6.text:=vAgenda[Base.PsReg].Rua;
 Form1.Edit7.text:=vAgenda[Base.PsReg].Referencia;
end;

procedure TForm3.FormActivate(Sender: TObject);
var
 col : longint;
 lin : longint;
 RegN: integer;
 Reg: TPessoasReg;
begin
 StringGrid1.Cells[1,0]:='Cliente Nš :';
 StringGrid1.cells[2,0]:='Nome :';
 StringGrid1.cells[3,0]:= 'Telefone :';
 StringGrid1.Cells[4,0]:='Morada :';
 StringGrid1.cells[5,0]:='NIB :';
 StringGrid1.cells[6,0]:= 'NIF :';
 StringGrid1.cells[7,0]:= 'Freguesia :';
 StringGrid1.cells[8,0]:= 'e-Mail :';
 ComboBox1.Clear;
 Seek (PesArq,0);
 lin:=1;
 while Not Eof (PesArq) do 
begin
 Read(PesArq,Reg);
 StringGrid1.Cells[0,lin]:= inttostr(lin);
 StringGrid1.cells[1,lin]:=reg.Cod;
 StringGrid1.Cells[2,lin]:=Reg.Nome;
 StringGrid1.cells[3,lin]:=reg.Telefone;
 StringGrid1.cells[4,lin]:=reg.Bairro;
 StringGrid1.Cells[5,lin]:=reg.Numero_Res;
 StringGrid1.Cells[6,lin]:=Reg.Numero_Ap;
 StringGrid1.cells[7,lin]:=reg.rua;
 StringGrid1.cells[8,lin]:=reg.Referencia;
 lin:=lin + 1;
 ComboBox1.Items.Add(reg.Nome);
end;
 Form3.StringGrid1.RowCount:= Lin;
end;

procedure TForm3.DBGrid1DblClick(Sender: TObject);
var
 RegN: integer;
 Reg: TPessoasReg;
begin
 RegN:=StringGrid1.row -1;;
 Unit4.LerArq (PesArq,RegN,Reg);
 Form1.Edit1.text:=vAgenda[Base.PsReg].Nome;
 Form1.Edit2.text:=vAgenda[Base.PsReg].Telefone;
 Form1.Edit3.text:=vAgenda[Base.PsReg].Bairro;
 Form1.Edit4.text:=vAgenda[Base.PsReg].Numero_Res;
 Form1.Edit5.text:=vAgenda[Base.PsReg].Numero_Ap;
 Form1.Edit6.text:=vAgenda[Base.PsReg].Rua;
 Form1.Edit7.text:=vAgenda[Base.PsReg].Referencia;
end;

end.
