I'm still a bit fuzzy with generics in Delphi, but have been using
TObjectList<> quite widely. Now I have a situation where I have a base class with such a private field, but needs to be created for an arbitrary class, also inherited from another base.
To clarify, I have two base classes:
TItem = class;
TItems = class;
TItemClass = class of TItem;
TItem = class(TPersistent)
TItems = class(TPersistent)
constructor Create(AItemClass: TItemClass);
destructor Destroy; override;
function Add: TItem;
This pair of classes is then further inherited into more specific classes. I'd like the object list to be shared for all of them, while each holds actually a different type internally.
TSomeItem = class(TItem)
TSomeItems = class(TItems)
function Add: TSomeItem; //Calls inherited, similar to a TCollection
Now the problem is when it comes to creating the actual object list. I'm trying to do it like this:
constructor TItems.Create(AItemClass: TItemClass);
However, the code insight complains about this:
Even more, the compiler has yet a different complaint:
Where, I do in fact have
System.Generics.Collections used in this unit.
What am I doing wrong here, and how should I do this instead?