3 levels objects...need help.

From: Bob Bedford (bob_at_bedford.com)
Date: 10/30/03


Date: Thu, 30 Oct 2003 13:48:05 +0100

I'm trying to coding "Object oriented" and I need help: TPlane.GroupList is
an objectList of TGroup, and TGroup.PassList is an objectList of
TPassDetail.

I must manage a plane (TPlane), a Group of Passengers (TGroup) and passenger
detail (TPassDetail). Here is the code:
  TPassDetail = Class(TObject)
    FirstName : ShortString;
    LastName : ShortString;
    InfName : ShortString;
    Name : ShortString;
    ClientID : Integer;
    GroupID : Integer;
    Color: TColor;
  end;

  TGroup = Class(TObject)
    GroupId : Integer;
    Plane_index : integer;
    PassList : TObjectList;
  public
    constructor create;
    destructor destroy;override;
    Procedure AddPassenger(PassDetail:TPassDetail);
    Procedure DelPassenger(PassDetail:TPassDetail);
  end;

  TPlane = Class(TObject)
    Callsign : shortString;
    TotalSeats : integer;
    AvailableSeats : integer;
    GroupList : TObjectList;
  Public
    constructor create;
    destructor destroy;override;
    function TestAdd(Group:TGroup):boolean;
    Procedure ResetPlaces;
    Procedure AddGroup(Group:TGroup);
    Procedure AddPassenger(Passenger:TPassenger);
    Procedure DelPassenger(Passenger:TPassenger);
  end;

I'm trying to create a function that Creates a Passenger in an airplane.
This is because I have many grids for managing seats in many aircrafts, and
I may switch passengers between aircrafts. So when I do a Drag&Drop between
aircrafts, I want to add a new passenger in an aircraft and remove him from
the first one. So I don't know if AddPassenger goes in TPlane or not (as
TPlane don't know that in his GroupList they are Passengers, or should I
first call TGroup.addPassenger and then Tplane.AddGroup ??? a Group is done
if they have the same GROUPID.

Something else: What does not sound good to me, is TPassDetail.GroupID (as
this is stored by his container, the TGroup object). It's there any way, for
a passenger, to know in wich group it is in without adding this field in the
TPassDetail object ???

BoB



Relevant Pages

  • Re: 3 levels objects...need help.
    ... > TGroup = Class ... > I'm trying to create a function that Creates a Passenger in an airplane. ... > I may switch passengers between aircrafts. ... So I don't know if AddPassenger goes in TPlane or not (as ...
    (borland.public.delphi.language.objectpascal)
  • Re: 3 levels objects...need help.
    ... >seats in the aircrafts and avoid to split them if possible. ... and move the group rather than the group passenger. ... give the groups a property Owner: TPlane instead of the PlaneIndex ...
    (borland.public.delphi.language.objectpascal)
  • Re: 3 levels objects...need help.
    ... splitting them: ... in the aircrafts and avoid to split them if possible. ... when I Drag&Drop the first passenger from aircraft2 ... aircraft1, then, when I Drag&Drop a second passenger, it will be put in the ...
    (borland.public.delphi.language.objectpascal)
  • Re: 3 levels objects...need help.
    ... > TGroup.PassList is an objectList of TPassDetail. ... > TGroup = Class ... BoB, ... look up the passenger group and do the actual move based ...
    (borland.public.delphi.language.objectpascal)