Instances of interfaces ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Instances of interfaces ?

Adriaan van Os-2
Section 7.1 Definition in Chapter 7 Interfaces of the FreePascal Language Reference says

        "Instances of interfaces cannot be created directly: instead, an instance of a class implementing
the interface must be created."

However, I assume that FreePascal classes (inheriting from interfaces) are (unlike C++ classes) not
binary compatible (on Win32) with interfaces ? In other words, when I need to pass an instance of
an interface to Win32 COM, I have to call CoCreateInstance ?

Regards,

Adriaan van Os

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Instances of interfaces ?

Michael Van Canneyt


On Fri, 10 Oct 2014, Adriaan van Os wrote:

> Section 7.1 Definition in Chapter 7 Interfaces of the FreePascal Language
> Reference says
>
> "Instances of interfaces cannot be created directly: instead, an
> instance of a class implementing the interface must be created."
>
> However, I assume that FreePascal classes (inheriting from interfaces) are
> (unlike C++ classes) not binary compatible (on Win32) with interfaces ? In
> other words, when I need to pass an instance of an interface to Win32 COM, I
> have to call CoCreateInstance ?

No, you can pass the interface pointer directly:

MyIntf : IMyInterface;

begin
   MyIntf := MyClassInstance as IMyInterface;
end;

Then pass on MyIntf.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Instances of interfaces ?

Adriaan van Os-2
Michael Van Canneyt wrote:

> No, you can pass the interface pointer directly:
>
> MyIntf : IMyInterface;
>
> begin
>   MyIntf := MyClassInstance as IMyInterface;
> end;
>
> Then pass on MyIntf.
>

Thanks for the reply. That simplifies things.

Regards,

Adriaan van Os
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal