[fpc-pascal] What happens when assigning interfaces?

Sven Barth pascaldragon at googlemail.com
Fri Jul 10 07:31:52 CEST 2020


Am 10.07.2020 um 03:02 schrieb Ryan Joseph via fpc-pascal:
>
>> On Jul 10, 2020, at 12:23 AM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> (so that it points to the VMT generated for the interface)
> So, it sounds like what the interface actually is, is a pointer to VMT table.

Correct.

> The VMT is generated with the class that implements the interface? Does it have to do a lookup to find the VMT table, like calling Supports() does?

Yes, the VMT belongs to the class. It contains interface thunks that 
adjust the Self pointer back to what the class expects before jumping(!) 
to the correct methods.

A lookup is only necessary if you use e.g. "SomeClass as SomeIntf". In 
the case of your example the compiler knows that TMyClass implements 
IFoo and thus can simply adjust the Self pointer.

Regards,
Sven


More information about the fpc-pascal mailing list