unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, uConst;
type
TForm1 =
class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
function Get_personen(
Index: Integer): TPerson;
procedure Set_personen(
Index: Integer; Rec: TPerson);
private
procedure StringGridInit;
public
property personen[
index: Integer]: TPerson
read Get_personen
write Set_personen;
end;
var
Form1: TForm1;
fpersonen:
array[1..9]
of TPerson;
implementation
uses Unit2;
{$R *.dfm}
function TForm1.Get_personen(
index: Integer): TPerson;
begin
Result := fpersonen[
index];
end;
procedure TForm1.Set_personen(
index: Integer; Rec: TPerson);
begin
fpersonen[
index] := Rec;
end;
procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
form2: TForm2;
begin
form2 := TForm2.Create(Self);
//ID an Form2 übergeben
form2.edit4.text := IntToStr(personen[StringGrid1.Row].id);
case form2.ShowModal
of
mrOk:
begin
fpersonen[StringGrid1.Row].vorname := form2.edit1.text;
fpersonen[StringGrid1.Row].nachname := form2.edit2.text;
fpersonen[StringGrid1.Row].geburtstag := StrToDate(form2.edit3.text);
StringGridInit;
end
end;
form2.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
//Felder mit beispielwerten füllen
for i := 1
to 9
do begin
fpersonen[i].id := i;
fpersonen[i].vorname := '
Willi ' + IntToStr(i);
fpersonen[i].nachname := '
Mustermann';
fpersonen[i].geburtstag := StrToDate('
31.12.1999');
end;
StringGridInit;
end;
procedure TForm1.StringGridInit;
var i: Integer;
begin
with StringGrid1
do
begin
RowCount := length(fpersonen)+1;
Cells[0,0] := '
ID';
Cells[1,0] := '
Vorname';
Cells[2,0] := '
Name';
Cells[3,0] := '
Geburtsdatum';
end;
for i := 1
to length(fpersonen)
do with StringGrid1
do
begin
Cells[0,i] := IntToStr(fpersonen[i].id);
Cells[1,i] := fpersonen[i].vorname;
Cells[2,i] := fpersonen[i].nachname;
Cells[3,i] := DateToStr(fpersonen[i].geburtstag);
end
end;
end.