I see your point, is there a particular reason why you use TObjectList, you could always use TList which instead of resulting with TObject TList results the pointer and you can base your own class on this.. e.g.Originally Posted by Gadget
[pascal]
type
TCreature = Class
// TCreature code
public
Name: String;
procedure DoAction;
end;
TCreatures = Class(TList)
private
function GetCreature(Index: Integer): TCreature;
public
function Add(Name: String): Integer;
property Items[Index: Integer]: TCreature read GetCreature; default;
end;
implementation
//----< TCreature >----//
procedure TCreature.DoAction;
begin
// Action
end;
//----< TCreatures >----//
function TCreatures.GetCreature(Index: Integer): TCreature;
begin
Result := Nil;
If (Index < 0) Or (Index > Count-1) Then Exit;
Result := TCreature(inherited Items[Index]);
end;
function TCreatures.Add(Name: String): Integer;
var
nCreature: TCreature;
begin
nCreature := TCreature.Create;
nCreature.Name := Name;
Result := inherited Add(nCreature);
end;
[/pascal]
and with this you can do what you want: Players[i].DoAction;
I find using this is a lot easier to deal with
hope it helps..
Bookmarks