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

Sven Barth pascaldragon at googlemail.com
Sun Oct 6 13:09:44 CEST 2013


On 06.10.2013 01:46, Daniel Gaspary wrote:
> On Sat, Oct 5, 2013 at 8:27 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
>> 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.
>
> I believed that the location that matters, in this case,  was only the
> object instantiation (program/implementation body), because it was, in
> both cases, after the helper declaration. A little weird.

No. Whenever you call a method (either inside a class using (implicit) 
Self or outside using a variable) the compiler checks whether a helper 
for that type is in scope and uses that if it is. It has nothing to do 
with object instantiation (that would be more for Traits/Mixins: 
http://en.wikipedia.org/wiki/Trait_%28computer_programming%29 ).

Regards,
Sven




More information about the fpc-pascal mailing list