No, that is wrong. Do not specialize to the root class (TObject) but to the class you actually mean to use: TfpgObectList has already the postfix modifier<T:class>.
What that means is that the list will only accept class instances (class) of type T.
What is so difficult to understand?
(btw: you are out of form, lately, Jamie )
Generics are kind of macro for classes. The T is replaced by the TObject descendent class specifier (of course including TObject) specified in the specialization for the function.
Takes the specified class as replacement for <T> and returns the specified class for function returning (in the generic class) without need to transtype.
I have frequently subclassed TFPObjectList .Get, Items etc (using helpers) to return the class that were stored in the list.
@BrunoK
You can not add nil, because nil is untyped.
Wrong nil is of type Pointer. TObject is Class(Pointer). Its definition is TObject = Pointer;
WHAT are you trying to achieve?
Maybe casting nil to Tobject will be accepted but is bad code: Add(TSomeObject(nil));
Why mess up with transtyping. You always can pass a descendant class to a function accepting a parent Class Type (but not the reverse). TObject descends from Pointer, nil is pointer.
But I would reconsider my design first. Because class instances are pointers and you 'add' duplicates.(nil is a pointer type)
I don't think that is what you want? Describe it better.
Of course my items are not just pointers, the example was the smallest that shows that
inherited; is not compiled as i
nherited Create; as is generally accepted. I don't understand why so I ask.
TFPList and immediate descendants do not give shit about duplicates
Then I can explain it.
Are you maybe trying to create storage for uninitialized future instances? Then you are clueless.(and you are not a beginner)
Better description - not the code, but its purpose - leads to better help.
Implementation of a circular buffer using a TFPObjectList but using a generic (for convenience .... ha ha ha). Inheritance is so misunderstood in this community that you have TObjectList using a side FList: TFPList class to hold its items instead of simply subclassing TObjectList = class (TFPList) ... ridiculous but not dramatic.