E2568 Can't create new instance without CONSTRUCTOR constraint in type parameter declaration (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Error and Warning Messages (Delphi)

This occurs when the generic type is derived from a class that has an implicit constructor and the default constructor clause is not mentioned.


program E2568;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
TMyClass1 = class

end;
TMyClass2<T: TMyClass1> = class // Fix: replace < T : TmyClass1> with <T : TMyClass1, constructor> 
public
procedure Add;
end;

procedure TMyClass2<T>.Add;
begin
T.Create(nil); //E2568
end;

begin
  Writeln('E2568 Cannot create new instance without CONSTRUCTOR constraint in type parameter declaration');
end.