Say I have a base class:
TPart = class
private
FPartId: Integer;
public
property PartId: Integer read FPartId write FPartId;
end;
and I have a generic list for this:
TPartList = class(TObjectList<TPart>)
public
function IndexOfPart(PartId: Integer): Integer;
end;
Now, if I descend from my TPart:
TModulePart = class(TPart)
private
FQuantity: Integer;
public
property Quantity: Integer read FQuantity write FQuantity;
end;
I want to now create a descendent of TPartList but be able to return me a TModulePart item. Doing this:
TModulePartList = class(TPartList)
end;
will by default think that Items property is of type TPart and not TModulePart (naturally). I don’t want to do:
TModulePartList = class(TObjectList<TModulePart>)
end;
because then I miss out inheriting from common methods I might have in TPartList.
Is it possible to do?
Thanks
You can do what you want like this:
You can add even more flexibility if you design it like this: