Can someone explain why I get the "Incompatible type" error (Delphi XE3) in the following program (see comments at the bottom of the code for details) when I omit the optional parameter for the constructor?
program Test; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.Classes; type BaseClass = class(TObject); ChildClass = class(BaseClass); GenericBaseClass<T> = class public constructor Create(Fixed: Integer); end; GenericClass<T: BaseClass> = class(GenericBaseClass<T>) public type TMyProc = procedure (DataObject: T) of object; public constructor Create(Fixed: String; Optional: TMyProc = nil); end; constructor GenericClass<T>.Create(Fixed: String; Optional: TMyProc); begin inherited Create(12); end; constructor GenericBaseClass<T>.Create(Fixed: Integer); begin inherited Create(); end; var Gc: GenericClass<ChildClass>; begin // this call is okay Gc := GenericClass<ChildClass>.Create('', nil); // this call fails: E2010 Incompatible types: 'ChildClass' and 'T' Gc := GenericClass<ChildClass>.Create(''); end.
source share