unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
TMensch =
class
private
FName :
String;
FGebdatum :
String;
FMaennlich : Boolean;
FVater : TMensch;
FMutter : TMensch;
protected
Kinder : TStringList;
Constructor Create( pName:
String);
Destructor destroy;
property Vater : TMensch
read FVater
write FMutter;
property Mutter: TMensch
read FMutter
write FMutter;
property Maennlich : boolean
read FMaennlich
write FMaennlich;
property Name :
String read FName;
property Geburtsdatum:
String read FGebdatum;
function erzeuge_kind(elter: TMensch;
name:
String): TMensch;
function ermittle_geschwister: TStringlist;
end;
// Ende Class TMensch
var
Form1: TForm1;
Vater: TMensch;
Mutter: TMensch;
Kind: TMensch;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Vater := TMensch.Create('
Steffen');
Vater.Maennlich := true;
Mutter := TMensch.Create('
Kathrin');
Mutter.Maennlich := False;
Kind := Mutter.erzeuge_kind(Vater,'
Philipp');
end;
Constructor TMensch.Create( pName:
String);
begin
FName := pName;
FGebdatum := DateToStr(Date);
end;
Destructor TMensch.Destroy;
var i: Integer;
myMensch: TMensch;
begin
IF self.Kinder.Count <> 0
THEN
FOR i:=0
TO self.Kinder.Count-1
DO
BEGIN
myMensch := self.Kinder.Objects[i]
as TMensch;
IF myMensch.Vater = self
THEN
myMensch.Vater :=
NIL
ELSE
myMensch.Mutter :=
NIL;
END;
self.Free;
end;
function TMensch.ermittle_geschwister: TStringlist;
var myList: TStringList;
i: Integer;
begin
IF self.Kinder.Count = 0
THEN
BEGIN
ermittle_geschwister :=
Nil;
exit;
END;
TRY
myList := TStringList.Create;
FOR i:=0
TO self.Kinder.Count-1
DO
myList.Add(self.Kinder.Strings[i]);
Except ON E:
Exception DO
END;
result := myList;
myList.Free;
end;
function TMensch.erzeuge_kind(elter: TMensch;
name:
String): TMensch;
var Kind: TMensch;
begin
IF ((elter =
NIL)
OR (self.Maennlich = elter.Maennlich))
THEN Kind :=
NIL
ELSE
BEGIN
Kind := TMensch.Create(
name);
Kind.Maennlich := true;
Kind.Vater := elter;
Kind.Mutter := self;
elter.Kinder.AddObject(
name,Kind);
self.Kinder.AddObject(
name,Kind);
END;
result := Kind;
end;
end.