[fpc-pascal]Mapping Object Pascal Classes to C++ Classes

memsom at interalpha.co.uk memsom at interalpha.co.uk
Wed Nov 13 17:50:34 CET 2002


> I don't think so. I guess it works only because Borland C++ is used and 
> Delphi and BC++ use the same back end and probably a similiar VMT generation.

I think it's the way Delphi is implemented. It also works when the DLL is 
compiled with MinGW, which certainly isn't Borland compatible in the same way 
as BC++ is. I just tested it. Further, the C++ class doesn't have to be 
abstract as Rudy suggests, because I altered it to return the 'TestClass' in my 
example, and it still works.

> Further, these methods are limited: no multiple inheritance, no exceptions 
> etc.. Its use depends on what you want to do.

If you write C++ reserving Multiple Inheritence for extremes, this shouldn't be 
a problem. However, in truth, you're right. Many C++ programmers get lost in 
the wonders of multiple inheritence. Surely Exceptions could be handled in some 
way? a simple mapping in the same manour, and some glue code to 'catch' the 
exception and pass it to Pascal if it is unhandled in C++.

> Afaik you're one of the BeFPC people, right? 
Yeah, except I'm on hiatus from that project. There are two French guys leading 
up at the moment, and they are wrapping the API directly with a different 
approach to that I started with. I want to wrap the API in a VCL/LCL style 
using a flattened universal API. This will get picked up at some point in the 
new year. The groundwork is there, but I have to make it more generic.

> If you want a clean mapping of 
> the gui classses from C++ to pascal, we can talk about C++ classes support in 
> FPC 1.1. The question is whether it is possible, it depends on the involved 
> C++ language features.

I think it would be cool if FPC does it on this level, with some 'behind the 
scenes' glue code to pad out the problems you've noted above. I think it works 
for Delphi because Borland altered the VMT to mimic that of C++ on the Windows 
platform to enable COM to work (For Delphi 2 before interfaces existed.)
 
> E.g. if exceptions are used, things get rather complicated. In this
> case I would suggest to modify h2pas to eat C++ and create wrappers as 
> usual which do the exception conversion.

The other guys have written a class mapper of sorts. I haven't really been 
keeping up with them. The only reason I stumbled onto this article was that I 
was looking into an automated C++ class flattener to help me use Muscle in 
Delphi (http://www.lcscanada.com/muscle/index.html). As muscle will compile 
using BC++ 5.5.1, I can probably map most of it using this technique. 
Supporting FPC would be cool too.

Anyway, with the new GCC3.x 'universal' ABI, shouldn't it all become a bit 
easier soon? :-)

Matt


---------------------------------------------
This message was sent using Mistral WebMail.
http://www.mistral.co.uk/






More information about the fpc-pascal mailing list