[fpc-pascal] Passing a CORBA interface as parameter
Sven Barth
pascaldragon at googlemail.com
Sat Dec 21 14:00:09 CET 2019
Am 20.12.2019 um 16:17 schrieb Adriaan van Os:
>
> I would like to pass a CORBA interface-type as parameter and test for
> equality, So, for example, I have
>
> {$mode objfpc}
> {$interfaces corba}
>
> type
> IMyInterface = Interface
>
> [ '{34aad6d0-5884-4143-97c2-b6e330305ae3}']
>
> Function MyFunc : Integer;
> end;
>
> Now I can pass IMyInterface to TObject.GetInterface as the first
> parameter, which is of type TGuid in the declaration.
>
> However, if I use the same TGuid parameter type in my own procedure
>
> procedure TestInterfaceParameter
> ( const theInterface : TGuid);
> begin
> if IsEqualGUID
> ( theInterface, ITestInterface1)
> then writeln
> ( 'theInterface = ITestInterface1')
> end;
>
> then I run into the problem that IMyInterface is accepted as actual
> parameter of TestInterfaceParameter and of IsEqualGUID only if
> IMyInterface inherits from IUnknown (which I certainly don't want, as
> it is reference counted). Strangely, TObject.GetInterface does accept
> IMyInterface as a parameter. So where is the difference ? Is there
> some compiler magic involved in TObject.GetInterface ?
The important difference in this regard between COM and CORBA interfaces
is that for CORBA interfaces the "guid" is a ShortString, not a TGUID.
Thus the compiler allows to convert a CORBA interface to a ShortString.
For TObject.GetInterface this works, because it has a overload for
ShortString. ;) (this is document here:
https://www.freepascal.org/docs-html/current/ref/refse47.html#x100-1220007.6
)
Regards,
Sven
More information about the fpc-pascal
mailing list