Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the E2511 Type parameter 'T' must be a class type compiler error mean?

Following my previous question, I am attempting to compile the code from one of the answers there.

 type 
   TSearchableObjectList<T> = class(TObjectList<T>)
   end;

The compiler will not compile this and reports this error message:

[dcc32 Error]: E2511 Type parameter 'T' must be a class type

What does this error message mean, and how should I fix the code?

like image 624
Franz Avatar asked Jul 19 '13 08:07

Franz


1 Answers

TObjectList<T> includes a generic constraint that T is a class. The type declaration is as follows:

type
  TObjectList<T: class> = class(TList<T>)
    ...
  end;

You might think that constraints are inherited, but that is not the case. And so you need to include the constraint in your class. Specify the constraint like so:

type
  TSearchableObjectList<T: class> = class(TObjectList<T>)
    ...
  end;
like image 117
David Heffernan Avatar answered Oct 31 '22 18:10

David Heffernan