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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:29:22+00:00 2026-05-10T22:29:22+00:00

I have a class hierarchy, this one: type TMatrix = class protected //… public

  • 0

I have a class hierarchy, this one:

type TMatrix = class     protected       //...     public       constructor Create(Rows, Cols: Byte);     //... type   TMinMatrix = class(TMatrix)     private       procedure Allocate;       procedure DeAllocate;     public       constructor Create(Rows, Cols: Byte);       constructor CreateCopy(var that: TMinMatrix);       destructor Destroy;   end; 

So as you see, both derived and base class constructors have the same parameter list. I explicitly call base class constructor from derived one:

constructor TMinMatrix.Create(Rows, Cols: Byte); begin    inherited;    //... end; 

Is it necessary to explicitly call base class constructor in Delphi? May be I need to put overload or override to clear what I intend to do? I know how to do it in C++ – you need explicit call of a base class constructor only if you want to pass some parameters to it – but I haven`t much experience in Delphi programming.

  • 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. 2026-05-10T22:29:23+00:00Added an answer on May 10, 2026 at 10:29 pm

    As far as I know, there are two separate issues here:

    Making sure the child class’ constructor calls the base class’ constructor

    You’ll have to explicitly call the base class’ constructor:

    constructor TMinMatrix.Create(Rows, Cols: Byte); begin    inherited;    //... end; 

    Making sure the child class’ constructor overrides the base class’ constructor

    You’ll also have to make the child class’ constructor override, and the base class’ constructor virtual, to make sure the compiler sees the relation between the two. If you don’t do that, the compiler will probably warn you that TMinMatrix’s constructor is ‘hiding’ TMatrix’s constructor. So, the correct code would be:

    type TMatrix = class     protected       //...     public       constructor Create(Rows, Cols: Byte); virtual;    // <-- Added 'virtual' here       //... type   TMinMatrix = class(TMatrix)     private       //...     public       constructor Create(Rows, Cols: Byte); override;   // <-- Added 'override' here       constructor CreateCopy(var that: TMinMatrix);       destructor Destroy; override;                     // <-- Also make the destructor 'override'!   end; 

    Note that you should also make your destructor override.

    Introducing a constructor with different parameters

    Note that you can only override a constructor with the same parameter list. If a child class needs a constructor with different parameters, and you want to prevent the base class’ constructors from being called directly, you should write:

    type TMyMatrix = class(TMatrix) //... public   constructor Create(Rows, Cols, InitialValue: Byte); reintroduce; virtual; //... end  implementation  constructor TMyMatrix.Create(Rows, Cols, InitialValue: Byte); begin   inherited Create(Rows, Cols);   // <-- Explicitly give parameters here   //... end; 

    I hope this makes things more clear… Good luck!

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

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this: $("td").click(function() { column = 1 + $(this).prevAll().size(); //… May 11, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer function generateEventsTable($dateStr) { $days = convert_date_to_day_number( $today ); foreach (… May 11, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer First of all you have a for loop with only… May 11, 2026 at 7:56 pm

Related Questions

I have a class hierarchy, this one: type TMatrix = class protected //... public
.NET 3.5, C# I have a web app with a search feature. Some of
How do you go about changing the subtype of a row in NHibernate? For
How does one go about and try to find all subclasses of a given
I have this code to represent bank: class Bank { friend class InvestmentMethod; std::vector<BaseBankAccount*>

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.