[Lazarus] inherited in autocode

Marcos Douglas B. Santos md at delfire.net
Sun Jan 13 01:09:36 CET 2019


On Sat, Jan 12, 2019 at 8:45 PM Martin Frb via lazarus
<lazarus at lists.lazarus-ide.org> wrote:
>
> On 12/01/2019 22:54, Martok via lazarus wrote:
> > Am 12.01.2019 um 22:28 schrieb Martin Frb via lazarus:
> >> Same for constructors, if the parent constructor changes its argument
> >> list, it will no longer be called.
> > It does generate code, but it calls *any* inherited constructor that matches the
> > signature:
> >
> >    type
> >      TA = class
> >        constructor Create(extra:Boolean);
> >      end;
> >      TB = class(TA)
> >        constructor Create;
> >      end;
> >
> >    constructor TA.Create(extra: Boolean);
> >    begin
> >      inherited Create;
> >      WriteLn('TA.Create');
> >    end;
> >    constructor TB.Create;
> >    begin
> >      inherited;                       // calls TObject.Create!
> because TObject has a matching constructor.
>
> Imagine it was
>
> constructor TB.Create(extra: integer);
>
> but was changed it TA.

IMHO, `inherited;` and `inherited Create;` should be the same behavior.
I don't use just `inherited;` and it isn't an issue for me, but it
looks like an inconsistency on the language.

Using the example, both constructors _must_ call TObject.Create
because `TA` haven't used `reintroduce` for the constructor.

Marcos Douglas


More information about the lazarus mailing list