[fpc-pascal] Understanding virtual methods

Sven Barth pascaldragon at googlemail.com
Tue Aug 20 20:09:44 CEST 2013


On 20.08.2013 15:39, Xiangrong Fang wrote:
> 1)  I didn't notice that my question are related to "modes" of fpc, i.e.
> turbo-pascal/delphi/objfpc.    If they are different, I would like to
> know more details, and I am more interested in objfpc mode, not those
> "compatibility" modes.

It has nothing to do with the modes besides the fact that the language 
construct "object" is available in all modes except macpas and that the 
language construct "class" is available in modes ObjFPC, Delphi, 
DelphiUnicode, MacPas (there also available as "object" for 
compatibility) and through the modeswitch "class". But objects and 
classes behave consistently to matter which mode is used.

> 2) I know override / overload are completely different thing, I am not
> trying to compare apple with orange.   Also, I am clear about the
> definition of virtual methods and their purpose.  What I need help is to
> explain the observations I found with my demo app (which is a bit
> different than I expected).  For example, why we need "reintroduce"
> while "overload" does the same job and better (it makes both methods
> available)?

"reintroduce" allows you to "break" the chain of virtual methods to add 
a new parameter and to hide the old method (for example, because calling 
the inherited method in your child class breaks things or whatever). 
"overload" just allows you to define two (or more) methods with the same 
name that have different parameter lists (result type of functions does 
not matter!). In mode ObjFPC this is normally done automatically while 
in mode Delphi you need to explicitely declare them as "overload".

I hope this cleared things up a bit.

Regards,
Sven



More information about the fpc-pascal mailing list