[fpc-pascal] Calling C++ object
Jonas Maebe
jonas.maebe at elis.ugent.be
Fri May 15 10:03:49 CEST 2009
On 15 May 2009, at 05:06, <Josh.Bowden at csiro.au>
<Josh.Bowden at csiro.au> wrote:
> I am trying to call a C++ object which is in a dll from a Pascal
> interface unit as described in Rudy's Delphi corner: (http://rvelthuis.de/articles/articles-cppobjs.html
> ). I use the inheritance method, making my C++ object a descendent
> from a Virtual ancestor.
>
> I end up with run time errors in both fpc and the cross 64 bit
> compiler (my desired target is Win64):
>
> error 210, (=R6025 - pure virtual function call)
Run time error 211 is for abstract function calls (= "pure virtual"
function calls). 210 = "Object not initialized". You have range
checking (or -CR) turned on. In this case, FPC inserts a run time
check before calling any method, which verifies that the object/class
is actually of the type that you declared in the source code.
If you make a class instance point to a C++ class instance, that check
will obvious fail.
> However, the code works using Delphi.
It relies on the VMT of the Pascal and C++ classes having an identical
layout. This may work with certain versions of certain C++ compilers
on certain platforms with Delphi and might also work in FPC (with the
same caveats), but it can break at any time and is simply a hack. I
would strongly recommend against using this at all, let alone in
production software.
Jonas
More information about the fpc-pascal
mailing list