Re: D5 - Class\Collection example??
- From: "Tom de Neef" <tdeneef@xxxxxxxx>
- Date: Sat, 13 Oct 2007 23:54:41 +0200
"Don @earthlink.net>" <don81846<NODAMSPAM> schreef in bericht
news:acb2h35oqr08o01fvnaa9h39tmpojtrklg@xxxxxxxxxx
Could someone please point me to, or post, a very simple code example
of a class heirarchy. Something like a person class that has a
collection of wives that each have a collection of addresses, etc.
type
Taddress = class
street : string;
etc...
end;
Tindividual = class
name : string;
sex : char;
partners : array of Tindividual;
addresses : array of Taddress;
constructor ceate;
procedure addPartner(partner : Tindividual);
end;
constructor Tindividual.create;
begin
inherited;
setLength(partners,0); // not strictly necessary
setLength(addresses,0);
end;
procedure Tindividual.addPartner(partner : Tindividual);
var m : integer;
begin
m:=high(partners)+1;
steLength(partners,m+1);
partners[m]:=partner;
// what to do about the partner of this partner ?
// It should be self, but you cannot call partner.addPartner(self)
// since it will result in an infinite loop !
end;
Tom
.
- Follow-Ups:
- Re: D5 - Class\Collection example??
- From: Maarten Wiltink
- Re: D5 - Class\Collection example??
- References:
- D5 - Class\Collection example??
- From: Don
- D5 - Class\Collection example??
- Prev by Date: Re: D5 - Navigation shortcuts
- Next by Date: Re: Line too long ???
- Previous by thread: D5 - Class\Collection example??
- Next by thread: Re: D5 - Class\Collection example??
- Index(es):
Relevant Pages
|