Note that there are some explanatory texts on larger screens.

plurals
  1. PODelphi: When does reintroduce hide ancestors and when does it show them?
    primarykey
    data
    text
    <p><strike>Today</strike> Recently on Stackoverflow i learned that:</p> <ul> <li><a href="https://stackoverflow.com/questions/3874330/delphi-how-to-hide-ancestor-constructors">reintroduce is used to <strong><em>hide</em></strong> ancestor constructors</a></li> <li><a href="https://stackoverflow.com/questions/3876484/delphi-how-to-add-a-different-constructor-to-a-descendant">reintroduce is used to <strong><em>show</em></strong> ancestor constructors</a></li> </ul> <p>i've been trying to make sense of it all, so here is a another, very specific question, <a href="https://stackoverflow.com/questions/3876040/delphi-understanding-constructors">supporting my main question dealing with constructors</a>.</p> <hr> <p><strong>Update:</strong> replaced the entire question:</p> <pre><code>TComputer = class(TObject) public constructor Create(Teapot: string=''); end; TCellPhone = class(TComputer) public constructor Create(Cup: Integer); overload; virtual; constructor Create(Cup: Integer; Teapot: string); overload; virtual; end; </code></pre> <p>When constructing TCellPhone, 3 constructors are avaible: </p> <ul> <li>Cup: Integer</li> <li>Cup: Integer; Teapot: string</li> <li>[Teapot: String = '']</li> </ul> <p>Question: Why is <code>constructor(Teapot: string='')</code> not being hidden?</p> <hr> <p>Now i added a 3rd descendant:</p> <pre><code>TComputer = class(TObject) public constructor Create(Teapot: string=''); end; TCellPhone = class(TComputer) public constructor Create(Cup: Integer); overload; virtual; constructor Create(Cup: Integer; Teapot: string); overload; virtual; end; TiPhone = class(TCellPhone) public constructor Create(Cup: Integer); override; end; </code></pre> <p>When constructing <code>TiPhone</code> <strong><em>four</em></strong> constructors are available:</p> <ul> <li>Cup: Integer</li> <li>Cup: Integer</li> <li>Cup: Integer; Teapot: string</li> <li>[Teapot: string = '']</li> </ul> <p>Why are there <strong><em>four</em></strong> constructors? i overrode one of the existing three. <strong>Edit:</strong> This may be a bug in code-insight, it shows me four - yet how could i possibly call then when two are the same.</p> <hr> <p>Using the original code again:</p> <pre><code>TComputer = class(TObject) public constructor Create(Teapot: string=''); end; TCellPhone = class(TComputer) public constructor Create(Cup: Integer); overload; virtual; constructor Create(Cup: Integer; Teapot: string); overload; virtual; end; </code></pre> <p>it's already known that <code>TCellPhone</code> has three constructors: </p> <ul> <li>Cup: Integer</li> <li>Cup: Integer; Teapot: string</li> <li>[Teapot: String = '']</li> </ul> <p>How do i alter the declaration of <code>TCellPhone</code> to hide the ancestor constructor? e.g. so that:</p> <pre><code>TNokia = class(TCellPhone) end; </code></pre> <p>will only have two constructors:</p> <ul> <li>Cup: Integer</li> <li>Cup: Integer; Teapot: string</li> </ul> <hr> <p>Now for the case where <code>reintroduce</code> is used to hide a non-virtual ancestor. In the previous case <code>TiPhone</code> has four constructors (ideally there would be only two - with <code>TComputer</code> somehow hiding its ancestor). But even if i can't fix <code>TComputer</code>, i can change <code>TiPhone</code> to only have the one:</p> <pre><code>TComputer = class(TObject) public constructor Create(Teapot: string=''); end; TCellPhone = class(TComputer) public constructor Create(Cup: Integer); overload; virtual; constructor Create(Cup: Integer; Teapot: string); overload; virtual; end; TiPhone = class(TCellPhone) public constructor Create(Cup: Integer); reintroduce; end; </code></pre> <p>Now <code>TiPhone</code> has only one constructor:</p> <ul> <li>Cup: Integer</li> </ul> <p>Reintroduce is normally only used to suppress the warning about hiding <strong>virtual</strong> ancestors. In this case:</p> <pre><code>Create(Teapot: string = '') </code></pre> <p>isn't virtual - yet i can still use reintroduce to hide it.</p> <hr> <p>But <strong>now</strong>, if i add another overloaded to <code>TiPhone</code>:</p> <pre><code>TiPhone = class(TCellPhone) public constructor Create(Cup: Integer); reintroduce; overload; constructor Create(Handle: String); overload; end; </code></pre> <p>Then suddenly the (previously hidden) ancestors come back:</p> <ul> <li>TiPhone.Create(7);</li> <li>TiPhone.Create('pink');</li> <li>TiPhone.Create(7, 'pink');</li> <li>TiPhone.Create();</li> </ul> <p>As you can see, i'm struggling to understand the logic of</p> <ul> <li>when something is hidden</li> <li>how to hide something</li> <li>when something is shown</li> <li>how to show something</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload