IMHO, the official reason for this limitation is that the compiler cannot handle this on its own.
This is just a flag for the compiler, which can also be set on its own, because the compiler really recognizes the fact that we need a constructor constraint. Therefore, the compiler can automatically process it, because the Generic class will be compiled before using this class.
Maybe we will get it with XE9
UPDATE
If TComponent is accepted as a class type without an open constructor without parameters, then the constructor constraint is useless, because this (extended sample from Nick) compiles and instantiates TComponent. Of course, it will not call the original TComponent.Create constructor (AOwner: TComponent), instead TObject.Create is called, but you have an instance of TComponent.
program Project3; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.Classes; type TSomeClass<T: class, constructor> = class function GetType: T; end; { TSomeClass<T> } function TSomeClass<T>.GetType: T; begin Result := T.Create; end; var SomeClass : TSomeClass<TComponent>; Component : TComponent; begin try SomeClass := TSomeClass<TComponent>.Create; Component := SomeClass.GetType; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.
UPDATE
TSomeClass<T: class, constructor>
has the same meaning as
TSomeClass<T: constructor>
because the record may have a constructor, but not without parameters, so we have an implicit restriction on the class. And turning it around
TSomeClass<T: class>
may have an implicit constructor constraint
source share