[fpc-pascal] Helpers: Implementation Location influencing the result

Sven Barth pascaldragon at googlemail.com
Sun Oct 6 01:27:18 CEST 2013


Am 05.10.2013 22:57 schrieb "Daniel Gaspary" <dgaspary at gmail.com>:
>
> I have created an example to show the different results I got due to
> where the implementation of a object is .
>
> The code is at http://pastebin.com/wY2qmZFm
>
> If you cut and paste the code block at "Location A" to the "Location
> B" the result of the program changes.
>
> At Location A the method of the helper is used. At Location B it is not.
>
> My questions are
>
> Is this right?

Yes.

> Why?

At location A the helper is not yet declared, thus GetAnotherString uses
the GetString function of its own class. On location B the helper is
already declared and thus the implementation of GetAnotherString will pick
up the helper's GetString function instead.

As normally helpers aren't declared in the same unit as their extended type
this isn't necessarily that obvious. ;)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20131006/ca25bd34/attachment.html>


More information about the fpc-pascal mailing list