Reputation: 49
Can somebody please tell me why I am getting the
Incompatible type: 'TChild' and 'Class of TChild'
TBase = class (TObject)
end;
TMyList<T: TBase> = class(TObjectList<T>)
end;
The error comes when I declare a child from the base class and try to create a list of TChild.
TChild = class (TBase)
end;
TChildList = TMyList<TChild>;
Upvotes: 1
Views: 680
Reputation: 613572
The code in the question is fine. Here is proof, a complete program that compiles:
program Project1;
{$APPTYPE CONSOLE}
uses
System.Generics.Collections;
type
TBase = class (TObject)
end;
TMyList<T: TBase> = class(TObjectList<T>)
end;
TChild = class (TBase)
end;
TChildList = TMyList<TChild>;
begin
end.
Clearly you need to edit the question to post code that exhibits the fault. Feel free to use the above as a template for how to provide a Delphi language SSCCE.
Upvotes: 4