Lazarus
Free Pascal => Beginners => Topic started by: XiJinping on September 12, 2019, 07:30:32 am
-
I tried interfaces in Free Pascal (delphi mode). And it seems that to compile a code with interfaces, I need to use directive (or com, I suppose). As I understand, these interfaces add runtime support of CORBA (or COM) IInterface. But is there any way to use simple interface like in any other OOP language without CORBA, COM and similar which will be ordinal, existing at compile time only classical interface?
-
The naming of {$interfaces com} and {$interfaces corba} is a bit misleading. The main difference is that if {$interfaces com} is set then an interface inherits from IUnknown (https://www.freepascal.org/docs-html/rtl/system/iunknown.html) which provides the methods _AddRef, _Release and QueryInterface which in turn allows the compiler to provide automatic reference counting for such interfaces as well as support for the as and is operators. It's suggested to inherit from TInterfacedObject (https://www.freepascal.org/docs-html/rtl/system/tinterfacedobject.html) in such cases (though in no way required). "CORBA" interfaces on the other hand are raw interfaces. They don't inherit from anything and they don't provide reference counting, so you yourself are responsible that the class instance implementing the interfaces is freed at the end.
-
So is it a correct suggestion: CORBA interfaces are the same as plain usual interfaces in other languages and they have not any runtime overhead to support CORBA? I mean something like C++ "interfaces" (with pure virtual functions)...
-
Indeed. When interfaces were added, the COM IUnknown dependency was seen as a potential portability problem, so a more base interface type was added.
As Corba was seen as a potential substitute for COM on other targets it got that name, but there is no real connection.
-
Thanks a lot.