cairnswm is right, classes are already pointers so there is no need to declare a Pointer type for them. So by declaring a pointer type, you are essentially creating a Pointer to a Pointer.
cairnswm is right, classes are already pointers so there is no need to declare a Pointer type for them. So by declaring a pointer type, you are essentially creating a Pointer to a Pointer.
This is exacly why i always tell around not to use pointersOriginally Posted by cairnswm
If you save your data in a proprietary format, the owner of the format owns your data.
<br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>
OK, so if I want to have a variable called Player that is actually an entry in the TObjectList, how do I do that?Originally Posted by savage
Thanks
http://www.c5software.co.uk (site is being developed at the moment)
(Not tested in Delphi)
[pascal]
Type
TItem = Class
<properties>
End;
var
Items : TList;
Procedure Create;
Var
I : TItem;
Begin
Items := TList.Create;
I := TItem.Create;
I.Init;
Items.Add(I);
End;
Function GetItem(Index : Integer) : TItem;
Begin
Result := TItem(Items[Index]);
End;
Player := GetItem(0);
[/pascal]
William Cairns
My Games: http://www.cairnsgames.co.za (Currently very inactive)
MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)
yeah, or linked lists, or if one want to access memory address directly, if I'm not wrong, the purpose of OOP is to relieve the programmer of using pointers; however; I see myself using them quite a lot..Originally Posted by "cairnswm
yeah, or linked lists, or if one want to access memory address directly, if I'm not wrong, the purpose of OOP is to relieve the programmer of using pointers; however; I see myself using them quite a lot..but in a strict sense they should be avoided.Originally Posted by "cairnswm
[quote="Anonymous"]yeah, or ]Originally Posted by cairnswm
I tend to like things more strongly typed so I would use something like
[pascal]
interface
type
TCreature = class( TObject )
// General Creature features
end;
TSpecialistCreatureA = class( TObject )
// SpecialistCreatureA features
end;
TSpecialistCreatureB = class( TObject )
// SpecialistCreatureB features
end;
TPlayer = class(TCreature)
// Specialise my Creature so it behaves more like a Player
end;
TCreatureManager = class( TObjectList )
protected
function GetItem(Index: Integer): TCreature;
procedure SetItem(Index: Integer; AObject: TCreature);
public
function Extract(Item: TCreature): TCreature;
function First: TCreature;
function Last: TCreature;
property Items[Index: Integer]: TCreature read GetItem write SetItem; default;
end;
implementation
{ TCreatureManager }
function TCreatureManager.Extract(Item: TCreature): TCreature;
begin
result := TCreature(inherited Extract(Item));
end;
function TCreatureManager.Last: TCreature;
begin
result := TCreature(inherited Last);
end;
function TCreatureManager.GetItem(Index: Integer): TCreature;
begin
result := TCreature(inherited Items[Index]);
end;
function TCreatureManager.First: TCreature;
begin
result := TCreature(inherited First);
end;
procedure TCreatureManager.SetItem(Index: Integer; AObject: TCreature);
begin
inherited Items[Index] := AObject;
end;
end.
[/pascal]
This does compile in Delphi.
If you really need to, you could also override the Add, Insert and other methods within the TObjectList decendant if you need to do some special things when adding etc. But as it is this code should handle managing a list of creatures and their decendents.
That code looks solid.
OOP at it's best!
Marmin^.Style
I agree on the specialised objects.
For Run-A-War I think there are 17 different classes. Lots of classes only really helps if you use polymorphism properly.
William Cairns
My Games: http://www.cairnsgames.co.za (Currently very inactive)
MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)
Bookmarks