[fpc-pascal] Wrong constructor returning the right object

Marco van de Voort marcov at stack.nl
Sun Feb 23 16:12:17 CET 2014


In our previous episode, Mark Morgan Lloyd said:

That logical, since the constructors are not an virtual; and override; pair.
 
> I find that if I explicitly decorate TB5500BaseUnit.Create() as virtual 
> and TB5500SPOUnit.Create() as override then TB5500SPOUnit.Create() is 
> called correctly. 

That's the normal way.

> I didn't think this was necessary, 

_why_ did you think this?

> but on reflection I 
> assume that it's because u is declared as a TB5500BaseUnit: the 
> variable's compile-time rather than run-time class is being used for the 
> constructor unless explicitly overridden.

In theory this kind of information could propagate in simple cases, but then
behaviour would differ between cases where this information could be
propagated (a deeper version called), and not (base version called).




More information about the fpc-pascal mailing list