Reference parent property of custom type
Posted on 2006-10-26
This is a cut down version of the sort of thing I have
MyType = ( item1, item2, item3);
TMyObject = class( TObject)
MyType: TMyType; // I want to remove this property
function GetMyType: TMyType;
property MyType: TMyType read GetMyType;
TMyObjectList = class( TObjectList)
MyType: TMyType; // i want to be able to reference this parent property from the objects in the objectlist
What I don't like is the fact that I have the property MyType in both the parent and child.
I would rather just keep it in the parent (objectlist), anmd be able to reference it from the child
Obviously I know this code below will not compile, but hopefully someone gets the idea of what I want to do.
I would assume that this might normally be done using a "class property", but they don't exist in delphi.
function TMyObject.GetMyType: TMyType;
Result := Parent.MyType