[fpc-pascal] Assigning Interface method to event handler
Jonas Maebe
jonas.maebe at elis.ugent.be
Wed May 25 16:49:32 CEST 2016
Michael Van Canneyt wrote on Wed, 25 May 2016:
> On Wed, 25 May 2016, Jonas Maebe wrote:
>
>> Sven Barth wrote on Wed, 25 May 2016:
>>
>>> An method pointer is always automatically constructed by the compiler
>>> consisting of the address of the method (here IFPReportFilter.RenderReport)
>>> and the instance that method belongs to (in this case the FReportFilter),
>>> so this will indeed work without problems.
>>> The question however is whether it is guaranteed to keep working and isn't
>>> merely the use of an implementation detail...
>>
>> It works by design. I can't think of a reason why it would stop working.
>
> What is the self in case of an interface that is not in a FPC program ?
In all cases we pass the unadjusted interface pointer. Such an
interface pointer is always a pointer to an interface VMT
pointer/address.
The interface method is required to be able to reconstitute the
interface's self pointer (the start of the instance that implements
this interface) from that. In both FPC and in regular COM, that
generally happens by some kind of stub code that is created for every
interface method implemented by a class, which subtracts the offset of
the interface's VMT in that specific class' instance layout from the
passed self pointere.
Jonas
More information about the fpc-pascal
mailing list