[fpc-devel] Linking to C++

Peter Popov ppopov at tamu.edu
Tue Jan 23 17:17:58 CET 2007


Yes, this is the original purpose of interfaces in Delphi 3 and later:  
reuse object code from different languages/executables through COM/DCOM or  
CORBA. Both define standards for RPC (Remote procedure calling) and  
passing arguments (type and size). An interface only exports member  
functions (any data members will create incompatibility problems: what is  
the data layout of the class, etc). Construction is by factory function,  
destruction is by reference counting (so it is done on the server side and  
the client does not have to do any memory management).

The implementation of CORBA is actually quite involved: the object  
hieararchy to be reused is described in a separate language (IDL -  
Interface Definition Language). Then, a CORBA compiler creates a thin  
layer of stub objects specific to the target programming language. The  
target programming language can then compile this thin layer, link at  
compile time, make a DLL and link at run time, etc. So, the server and  
client sides are independent and only share the object hierarchy  
description (in IDL). The client language always works with the stub  
object (compiled in the same langage). The stub transfers the arguments to  
the CORBA executable, whih passes them to the stub on the servers side.  
The server serves the result to the CORBE layer, the CORBA passes is to  
the client stub. So, the results is now visible to the client.

As far as I remember, Delphi 5 and on has an IDL compiler included, and  
can generate IDL code from an Object Pascal hierarchy.  So in FPC one can  
envision automatic generation of IDL description based on an interface  
hierarchy. There might, however, already be some parsers (independent of  
Borland) that do that.

A final remark. Code sharing through COM/DCOM can lead to the following  
"Hello World" program:
http://www.ffzg.hr/infosl/fun/HelloWorld.htm (see the master programmer  
example)

Peter


On Tue, 23 Jan 2007 05:56:09 -0600, Michael Schnell <mschnell at lumino.de>  
wrote:

>
> Thanks for the clarifying statement, Peter
>
> I's obvious that linking Object Pascal and C++ in that way is not  
> possible.
>
> OTOH, is interfaces not invented for object based inter-language  
> communication ?
>
> So an interface based DLL layer, converting the C++ API of the OS to  
> interfaces FP could use, might be a more decent way to go that to go  
> back to pure C.
>
> -Michael
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel




More information about the fpc-devel mailing list