0

I created a new descendant that overloads the base constructor

TJSONTOXML = class(TIpwJSON)
            private
               ...
            public
               constructor Create(AOwner: TForm; ALogLevel: Integer); reintroduce; overload;
            end;

but I forgot to change the previous create call

lIpwJSON := TIpwJSON.Create(Self);

to the new

lJSONToXML := TJSON2XML.Create(Self,lLevel);

Instead I just replaced the type so it was:

lJSONToXML := TJSON2XML.Create(Self);

It took me quite some time to figure this out ;-(

Is there a way to prevent this? I could do a dirty Create(AOwner) override with an Assert(False) but prefer a cleaner way.

Note: parent constructors were

public

  constructor Create(AOwner: TComponent); overload; override;
  constructor Create(AOwner: TComponent; OEMKey: string); reintroduce; overload;
Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
  • Why are you using `reintroduce` and `overload`? And how is the parent constructor declared? – David Heffernan Jun 19 '19 at 14:16
  • @DavidHeffernan Picked that from seeing it in the parent ;-) Question updated. – Jan Doggen Jun 19 '19 at 14:21
  • Do you understand what `reintroduce` does here? – David Heffernan Jun 19 '19 at 14:36
  • 1
    [this](https://stackoverflow.com/questions/1758917/delphi-pascal-overloading-a-constructor-with-a-different-prototype) might be interesting for you to read. Also read the other anwsers, not only the accepted – GuidoG Jun 19 '19 at 14:46
  • 2
    Seems like the wrong design. If you don't want to expose the functionality of the base class then why not use composition instead of inheritance? – J... Jun 19 '19 at 19:24

0 Answers0