Link to home
Start Free TrialLog in
Avatar of Dippen
Dippen

asked on

Wanting to create a TList subclass...

Hi! I'm rather new to classes and OOP, and I would like to create a class (TScriptObjectList) that is identical to TList BESIDES the fact that I want the Items property to return a pointer to the TScriptObject class instead (a class that I've created).
Can I accomplish that without having to duplicate the entire TList class? Overriding perhaps?

Like:
var
  MyScriptObject : TScriptObject;

MyScriptObject := MyScript.Children.Items[0];
(no typecasting needed!)

Thanks!

Daniel, Sweden
Avatar of snoop_doggy_dogg
snoop_doggy_dogg

Hey dude, I've done this before...you can't override the getter for TList, but you can redeclare the property getter and setter in your subclass to only allow TScriptObjects as long as whoever has your list object knows it as a TScriptList instead of a TList.  You also might want to look at TCollection and TCollectionItem...it might be more appropriate for what you're doing.

Cheers,
Woof!
ASKER CERTIFIED SOLUTION
Avatar of philipleighs
philipleighs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial