Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Delphi call inherited on overridden procedures if there is no explicit call

Does Delphi call inherited on overridden procedures if there is no explicit call in the code ie (inherited;), I have the following structure (from super to sub class)

TForm >> TBaseForm >> TAnyOtherForm

All the forms in the project will be derived from TBaseForm, as this will have all the standard set-up and destructive parts that are used for every form (security, validation ect).

TBaseForm has onCreate and onDestroy procedures with the code to do this, but if someone (ie me) forgot to add inherited to the onCreate on TAnyOtherForm would Delphi call it for me? I have found references on the web that say it is not required, but nowhere says if it gets called if it is omitted from the code.

Also if it does call inherited for me, when will it call it?

like image 630
Re0sless Avatar asked Sep 10 '08 09:09

Re0sless


2 Answers

No, if you leave the call to inherited away, it will not be called. Otherwise it would not be possible to override a method and totally ommit the parent version of it.

like image 75
Ralph M. Rickenbach Avatar answered Sep 30 '22 01:09

Ralph M. Rickenbach


It is worth mentioning that not calling inherited in Destroy of any object can cause memory leaks. There are tools available to check for this in your source code.

like image 33
mj2008 Avatar answered Sep 30 '22 02:09

mj2008