[fpc-pascal] What happens when assigning interfaces?

Sven Barth pascaldragon at googlemail.com
Thu Jul 9 19:23:54 CEST 2020


Am 09.07.2020 um 14:31 schrieb Ryan Joseph via fpc-pascal:
> Given the code below and the 2 cases can anyone explain what exactly the compiler does when the interfaces are assigned to? Does it copy a record like structure, call some internal functions, do runtime checks? I'm curious if they're doing more than I think they do.
>
> ============================
>
> {$mode objfpc}
> {$interfaces corba}
>
> program unit_name;
>
> type
>    IFoo = interface ['IFoo']
>    end;
>
> type
>    TMyClass = class (IFoo)
>    end;
>
> procedure DoSomething(i: IFoo);
> begin
> end;
>
> var
>    f: IFoo;
>    c: TMyClass;
> begin
>    // case A
>    f := c;
>    // case B
>    DoSomething(c);
> end.

As you're using CORBA or RAW interfaces a) will simply copy a shifted 
pointer to the 'c' class instance (so that it points to the VMT 
generated for the interface). And b) is a simple pointer passing.

Regards,
Sven


More information about the fpc-pascal mailing list