Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:23:38+00:00 2026-06-12T08:23:38+00:00

type TForm72 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public {

  • 0
type
  TForm72 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }    
  end;

  TTestForm = class(TForm)
  public
    constructor CreateTest(AOwner: TComponent); virtual;
  end;

  TTestForm1 = class(TTestForm)    
  public
    constructor CreateTest(AOwner: TComponent); override;
  end;

  TTest<T: TTestForm, constructor> = class(TObject)
  public
    class procedure Test;
  end;

var
  Form72: TForm72;

implementation

{$R *.dfm}

procedure TForm72.FormCreate(Sender: TObject);
begin
  TTest<TTestForm1>.Test;
end;

{ TTest<T> }

class procedure TTest<T>.Test;
var
  F: T;
begin
  F := T.CreateTest(Application);
  Form72.Caption :=  F.Name;
end;

{ TTestForm }

constructor TTestForm.CreateTest(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

{ TTestForm1 }

constructor TTestForm1.CreateTest(AOwner: TComponent);
begin
  inherited;
  Caption := 'Bang';
end;

end.

This code compiled in XE2, but fail with “[dcc32 Error] Unit71.pas(55): E2010 Incompatible types: ‘T’ and ‘procedure, untyped pointer or untyped parameter'” in XE3. What I did wrong, or compiler did wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:23:41+00:00Added an answer on June 12, 2026 at 8:23 am

    In fact this code highlights a compiler bug in XE2. In XE2, the code compiles when it should not. Remove the constructor constraint and the compilation fails with

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

    But the constructor constraint merely states that the class has a parameterless constructor. The documentation states:

    Constructor Constraints

    A type parameter may be constrained by zero or one instance of the
    reserved word “constructor”. This means that the actual argument type
    must be a class that defines a default constructor (a public
    parameterless constructor), so that methods within the generic type
    may construct instances of the argument type using the argument type’s
    default constructor, without knowing anything about the argument type
    itself (no minimum base type requirements).

    The fact that the presence or otherwise of the constructor constraint influences this code indicates that the XE2 compiler has a fault.


    In XE3 the code correctly fails to compile. The only way to call a constructor with the syntax T.Create is if you are using a constructor constraint and are calling a parameterless constructor. That is not the case here and so XE3 correctly reports a compilation error.

    You need some casting to make it compile.

    F := T(TTestForm(T).CreateTest(Application));
    

    This is a well-known trick to get around some of the quirks of the Delphi generics implementation’s handling of constructors. Although it looks messy, I believe that this code is what the language designers intended us to use. In my opinion, the change in behaviour is due to a bug fix and XE3 is behaving as designed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

type TMyForm= class(TForm) sg : TStringGrid; imgSortIt: TImage; ... procedure imgSortItClick(Sender: TObject); private {
type TPerson = class(TObject) name : string; constructor create(name : string); end; would trigger
type TParent=class public member1:Integer; end; TChild=class(TParent) public member2:Integer; end; TGArray<T: TParent>=class public function test:T;
this code works fine: procedure TForm2.Timer1Timer(Sender: TObject); var Text: string; begin SetLength (Text,555); GetWindowText
type TTest = class a: integer; end; TTest2 = class(TTest) b: integer; end; var
type Tmyclass = class(TObject) somearray: array of TSometype FBool: Boolean; Fint: Integer; Fstr: string;
type TSomeRecord = Record field1: integer; field2: string; field3: boolean; End; var SomeRecord: TSomeRecord;
Type ABFator a As Single b As Sinlge End Type Dim ABFactorArr(8) As ABFactor
type TDelphiSignature=record Signature:array [0..3] of LongWord; Version:string; end; const DelphiSignature:array [0..2] of TDelphiSignature=( (Signature:($384F3D26,$B83782C2,$034224F3,$833A9B17);Version:'Delphi
type Foo = class inherit Bar val _stuff : int new (stuff : int)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.