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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:34:47+00:00 2026-05-31T04:34:47+00:00

How to specify overridden method of which base class to call in Delphi? Let

  • 0

How to specify overridden method of which base class to call in Delphi?

Let say, a line of inheritance like this:
TObject -> … SomeMoreBaseClass … -> ParentClass -> MyClass

Suppose ParentClass has no Create(), but it has a Create(int = 0).
Such that when you call ParentClass.Create(), it actually calls ParentClass.Create(0)

Now, in the constructor Create() of MyClass, if I call “inherited;”, I found that I am not getting the ParentClass.Create(0), instead I am getting .Create() of the Base Classes or even TObject.

So, how can I make it to call ParentClass.Create()?

The easiest would be “inherited Create(0)”, but it doesn’t feel “right” enough.

(The ParentClass in my case is actually the System.Generics.Collections.TDictionary)

Code sample:

type

  TParentClass = class
  public
    constructor Create(n:Integer = 0);
  end;

  TDerivedClass = class(TParentClass)
  public
    constructor Create; // Note: no parameters
  end;

constructor TDerivedClass.Create;
begin
  // inherited; // this calls TObject.Create, not TParentClass.Create(0);
  inherited Create(0);
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-31T04:34:48+00:00Added an answer on May 31, 2026 at 4:34 am

    First of all, as @Cosmin explains in some detail, the question does not concern overridden methods. The question is about calling inherited methods.

    inherited Create;
    

    is the best you can do here. This calls the TDictionary<TKey,TValue> constructor passing the default ACapacity of 0.

    In fact it may even be preferable to write:

    inherited Create(0);
    

    and be quite explicit.


    My assumption is that your code looks like this:

    type
      TMyClass<TKey,TValue> = class(TDictionary<TKey,TValue>)
      public
        constructor Create;
      end;
    
    constructor TMyClass<K,V>.Create;
    begin
      inherited;
    end;
    

    I read the documentation for the inherited keyword in an attempt to understand the difference between inherited and inherited Create. The best clues are contained in the following excerpts:

    If inherited is followed by the name of a member, it represents a normal method call …

    and

    When inherited has no identifier after it, it refers to the inherited method with the same name as the enclosing method. In this case, inherited takes no explicit parameters, but passes to the inherited method the same parameters with which the enclosing method was called.

    This seems to hint that the two competing uses of inherited are treated differently.

    My understanding is that inherited results in a call to a constructor with matching parameters. In your case, TMyClass<K,V>.Create is parameterless and so the only matching constructor is that of TObject. Note that none of the constructors of TDictionary can match since they all take parameters.

    On the other hand, when you write inherited Create this is a normal method call. And so default parameters can be added to the method call. The crucial point is that this variant allows calling inherited methods with non-matching parameter lists.

    In my view, the inherited syntax with no following identifier should have been reserved for virtual methods.


    The designers of TDictionary<TKey,TValue> could have saved you from this unhappy fate. The constructors of TDictionary<TKey,TValue> should have been implemented like this:

    constructor Create; overload;
    constructor Create(ACapacity: Integer); overload;
    .....other constructors omitted
    

    Then the implementation for the parameterless constructor would simply be:

    constructor TDictionary<TKey,TValue>.Create;
    begin
      Create(0);
    end;
    

    Had this decision been taken, the parameterless constructor declared in TObject would have been hidden from any derived classes and your code would work as you intended.

    The problem you have encountered here is the result of an unhappy confluence of events involving overloading, default parameters, the parameterless constructor of TObject and the quirky syntax of inherited for constructors. Whilst writing inherited is highly readable and concise, it simply leads to confusion when overloaded methods are in play.

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

Sidebar

Related Questions

I would like to specify a constraint which is another type with a generic
Is there a way to override an abstract class's method signature which uses <T>
I wrote a class that allows a derivate to specify which of its properties
In Java... I am creating a class Foo which contains a method doAction(). My
I have 2 classes. Let's call them class A and class B. Class A
For simplicity's sake, lets say I have the following Abstract Base Controller Class: public
Let's say I have window.open (without name parameter), scattered in my project and I
Is there a way in C++ to write a concrete class which when another
I have a basic class 'HistoryItem' like so: public class HistoryItem private Date startDate;
I have a webservice with a method that takes a parameter of abstract base

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.