Reputation: 23
I need something like this:
function fn_get_all_propperties (obj : TObject) : TObjectList<TTypeKind>;
But: [DCC Error] uFuncMain.pas(20): E2511 Type parameter 'T' must be a class type
What type should be the result of a function?
Upvotes: 1
Views: 690
Reputation: 612794
The problem is that TObjectList
is defined as follows:
TObjectList<T: class> = class(TList)
....
end;
The T: class
in the definition means that the generic parameter T
is constrained to be a class
. But TTypeKind
is not a class. It is a value type.
So the compiler rejects your attempted generic instantiation as being invalid because it does not satisfy the constraint.
So you cannot use TObjectList<T>
here and instead should use TList<T>
. Your function should be defined like this:
function fn_get_all_properties(obj: TObject): TList<TTypeKind>;
Upvotes: 2