Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-10

Instances of interfaces ?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Adriaan van Os

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

Reply by email

Michael Van Canneyt
to Adriaan van Os
Adriaan van Os wrote 10 lines
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.

Reply by email

Adriaan van Os
to Michael Van Canneyt
Michael Van Canneyt wrote 10 lines
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

Reply by email