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 820027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:24:31+00:00 2026-05-15T02:24:31+00:00

I have reintroduced the form constructor in a base form, but if I override

  • 0

I have reintroduced the form constructor in a base form, but if I override the original constructor in a descendant form, the reintroduced constructor is no longer visible.

type
  TfrmA = class(TForm)
  private
    FWndParent: HWnd;
  public
    constructor Create(AOwner: TComponent; const AWndParent: Hwnd); reintroduce; overload; virtual;
  end;

constructor TfrmA.Create(AOwner: TComponent; const AWndParent: Hwnd);
begin
  FWndParent := AWndParent;
  inherited Create(AOwner);
end;

type
  TfrmB = class(TfrmA)
  private
  public
  end;

type
  TfrmC = class(TfrmB)
  private
  public
    constructor Create(AOwner: TComponent); override;
  end;

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

When creating:

  frmA := TfrmA.Create(nil, 0);
  frmB := TfrmB.Create(nil, 0);
  frmC := TfrmC.Create(nil, 0); // Compiler error

My work-around is to override the reintroduced constructor or to declare the original constructor overloaded, but I’d like to understand the reason for this behavior.

type
  TfrmA = class(TForm)
  private
    FWndParent: HWnd;
  public
    constructor Create(AOwner: TComponent); overload; override;
    constructor Create(AOwner: TComponent; const AWndParent: Hwnd); reintroduce; overload; virtual;
  end;

type
  TfrmC = class(TfrmB)
  private
  public
    constructor Create(AOwner: TComponent; const AWndParent: Hwnd); override;
  end;
  • 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-05-15T02:24:32+00:00Added an answer on May 15, 2026 at 2:24 am

    In your initial code your Create constructor hides the original Create. Which is why the compiler complains about TfrmC overriding a constructor it can no longer see from there.

    You would normally get a compiler message about this, but “reintroduce” suppresses this. Whenever you need “reintroduce” to suppress compiler messages, alarm bells should go off as it is an indication that you are breaking polymorphism. Doesn’t mean you shouldn’t use it, but you should be aware of the implications.

    In these cases, if I want to retain the ability to override the original constructor, I tend to add a different constructor, ie

    constructor CreateWithParent(AOwner: TComponent; const AWndParent: HWnd); virtual;
    

    and call the original constructor in its implementation. It does mean I need to call a different constructor, but as you already need to pass another parameter, that doesn’t seem like such a bad trade-off.

    Edit:
    As I mentioned in the comments, the compiler complains about tfrmC.Create(nil, 0); having too many parameters. It seems as though tfrmC.Create(AOwner) hides tfrmA.Create(AOwner, AWndParent); Thinking about it on the way home (traffic jams seem to have an advantage after all), there is an explanation for this.

    1) The overload on the tfrmA.Create serves no direct purpose other than to allow introduction of other constructors with the same name.
    2) The TfrmC constructor effectively hides the TfrmA constructor, reintroducing the signature that was hidden by the TfrmA constructor. In effect this isn’t an override of the original constructor but a re-introduction of a re-introduced one.
    3) I feel the compiler should have emitted a warning about this hiding. The reason it doesn’t is possibly the overload directive on the TfrmA constructor. When you remove that, you get an error about the TfrmC.Create declaration differing from the previous one.
    4) As the TfrmA constructor was hidden by TfrmC the compiler correctly complains about TFrmC.Create(nil, 0) having too many parameters.

    What is described under 2) becomes obvious when you add the signature of the TfrmA constructor to TfrmC with just the override directive. This constructor is then immediately redlined by the IDE. The reason: two constructors with the same name and a missing overload directive for the TfrmC constructor that only has the AOwner parameter.

    It also becomes clear when you comment out the second parameter in the instantiation of tfrmC and had only coded “inherited;” instead of “inherited Create(AOwner);” in its implementation. The compiler then complains about incompatible types.

    The latter could have been solved by using either “inherited Create(AOwner);” (as you did) or “inherited Create(AOwner, 0);”. While the latter would have ensured a walk back up the inheritance tree, the former would have jumped straight back to TForm1.Create.

    Using a slightly modified version of your code and provided TfrmC is instantiated with a single parameter, the result of “inherited Create(AOwner)” would have been:

    alt text http://www.bjmsoftware.com/delphistuff/overloading/InheritedCreate1Param.jpg

    while the result of “inherited Create(AOwner, 0);” would have been:
    alt text http://www.bjmsoftware.com/delphistuff/overloading/InheritedCreate2Params.jpg

    Adding overload to the TfrmC constructor as I suggested in the comments overrides the original TForm1.Create and allows for two constructors with the same name. This can be illustrated in the test project by turning on the TFRMC_OVERLOAD and INSTANTIATE2 conditional defines. This instantiates TfrmC with TfrmC.Create(nil, 0) and results in:

    alt text http://www.bjmsoftware.com/delphistuff/overloading/InheritedCreate2ParamsOverload.jpg

    Which shows TfrmB.Create being called for TfrmC as TfrmB is the first ancestor with an implementation for the two-parameter constructor. While instantiating TfrmC with TfrmC.Create(nil) (turn the INSTANTIATE2 conditional define back off), results in the same picture as the first or second (depending on the TWOPARAMS define).

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

Sidebar

Related Questions

I have the following superclass: unit DlgDefaultForm; type TDefaultFormDlg = class(TForm) published constructor Create(AOwner:
Have a singleton class for BNRItemStore, but when I tried to call it, I
have the following implementation $.ajax({ type: POST, url: /Member/SaveMember, data: $('form').serialize(), success: refreshGrid() how
have been playing with Cubepoints (wordpress plugin) and have installed the ranks module but
Have converted devise new session from erb to Haml but doens't work, this is
Have searched the database but need to specifically sum(of hours flown or days off)in
I have deleted a file a couple of times in git, but it keeps
have next code: class GameTexture { private: LPDIRECT3DTEXTURE9 texture; unsigned char *alphaLayer; UINT width,
Have a (rather complex) app that works fine on iOS 4 but fails on
Have been working in Ruby for a while, but usually in the context of

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.