newbie question sabout class design

From: Alan Mead (amead_at_comcast.net)
Date: 01/18/05


Date: Tue, 18 Jan 2005 02:10:04 -0600

I am writing a simulation where a population object has to hold
a series of people objects.

I'm using a TList to hold the people but I have to cast each time, like this:

Result := Result + Person(Peops.Items[i]).Fitness;

So, is TList the best way for one class to hold a series of objects?

And if so, one book recommends creating a wrapper around TList to avoid
the casts. I'm probably doing it wrong because I still have to cast.
Here's my wrapper:

  TPeopList = class(Tlist)
    public
      procedure Add(p: Person);
      constructor Create;
      destructor Destroy; override;
  end;

Which doesn't help at all. I guess because I need to add an Items
property. But I'm stuck here:

      property Items[i: Integer]: Person read ??? write ???; default;

I don't know what to put for the ??? marks...

And in general, can I get away with all of the methods being just an
inherited statement? Or do I need to make a cast:

procedure TPeopList.Add(p: Person);
begin
  inherited; // can it be this simple?
  inherited Add(pointer(p)); // or do I need to do this?
  ??? // or am I completely lost?
end;

Thanks!

-Alan