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

  • Home
  • SEARCH
  • 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 2017970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T09:00:59+00:00 2026-05-17T09:00:59+00:00

After having read Ian Boyd ‘s constructor series questions ( 1 , 2 ,

  • 0

After having read Ian Boyd‘s constructor series questions (1, 2, 3, 4), I realize I don’t quite grasp the literal meaning on what’s being hidden.

I know (correct me if I’m wrong) override‘s sole purpose is to be able to have polymorphic behavior, so that run-time can resolve a method depending on the actual type of an instance – as opposed to the declared type. Consider the following code:

type
  TBase = class
    procedure Proc1; virtual;
    procedure Proc2; virtual;
  end;

  TChild = class(TBase)
    procedure Proc1; override;
    procedure Proc2;            // <- [DCC Warning]
  end;

procedure TBase.Proc1;
begin
  Writeln('Base.Proc1');
end;
procedure TBase.Proc2;
begin
  Writeln('Base.Proc2');
end;

procedure TChild.Proc1;
begin
  inherited Proc1;
  Writeln('Child.Proc1');
end;
procedure TChild.Proc2;
begin
  inherited Proc2;
  Writeln('Child.Proc2');
end;

var
  Base: TBase;
begin
  Base := TChild.Create;
  Base.Proc1;
  Writeln;
  Base.Proc2;
  Base.Free;
  Readln;
end.

Which outputs:

Base.Proc1
Child.Proc1

Base.Proc2

The warning on TChild.Proc2 states that this method “will hide access to the base’s method of the same name“. What I see is, if I don’t override Proc2 I loose the ability of the method’s resolving to its actual type, not of its base type. How’s that hiding access to base’s method?

Further, down the documentation on the warning as a solution to the warning, it is stated that:

First, you could specify override to
make the derived class’ procedure also
virtual, and thus allowing inherited
calls to still reference the original
procedure.

Now, if I create a ‘TChild’ instance from a ‘TChild’ (no polymorphism), the inherited call in the non-overridden method clearly refers to the original procedure. If I create the ‘Child’ instance from a ‘TBase’, the call does not even resolve to a ‘TChild’ method, how could I call ‘Inherited’ that would refer to anything at all?

What am I misunderstanding?

  • 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-17T09:01:00+00:00Added an answer on May 17, 2026 at 9:01 am

    Amongs other thing, you won’t be able to define

    TGrandChild = class(TChild) 
      procedure Proc2; override;
    end; 
    

    because Proc2 that TGrandChild sees is the one from TChild that is not virtual. The TChild.Proc2 hide TBase.Proc2 from descendants.

    EDIT:

    In answer to Sertac’s comment:

    var 
      Base: TBase; 
      Child : TChild
    begin 
      Child := TChild.Create;
      Base := Child;
      Base.Proc2; 
      Child.Proc2;
    
      Base.Free; 
      Readln; 
    

    That will output

    Base.Proc2
    Base.Proc2
    Child.Proc2
    

    So, what seems to be a call to the same method twice is actually a call to 2 different methods. That makes code harder to understand (which is not practical) and yield unexpected behavior.

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

Sidebar

Related Questions

It seems to be a widely asked questions and after having read tons of
I'm still entangled in error handling problems. After having read and tried lots of
... after having just read http://www.cocoadev.com/index.pl?CocoaInsecurity ... I am curious to know about your
After googling and landing on SO and having read this other question Is it
How do you read the errors? I run after having .config -file at /home/aal/build/kernel.
Good morning. After having read the answer on a question about optimizing Excel Interop
After having read a lot of material on REST versioning, I am thinking of
So after having read a few different Big Nerd Ranch texts, as well as
I'm new to Objective-c and after having read some articles about good practices, it
After having read that QuickSilver was no longer supported by BlackTree and has since

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.