Results 1 to 5 of 5

Thread: Combining C++ and Delphi

  1. #1

    Combining C++ and Delphi

    Does anyone have experience on projects utilizing/mixing both Delphi and C++?

    There is little about it online and all of it comes from Embarcadero ( https://youtu.be/6f5UBL0bQ9U?t=420 ) , so a second opinion would be useful. Does it work as they say, or are there problems they are not mentioning?

    I ask this as a long term consideration, I update my Delphi every few years, and I could upgrade to full RAD studio next time, in case it is useful.
    Last edited by Thyandyr; 04-06-2017 at 07:09 PM.

  2. #2
    AFAIK it only works if your C++ compiler is Embarcadero's one too (i.e. RAD Studio).
    No signature provided yet.

  3. #3
    I've done this before with C (using gcc) and FPC. C++ would be a bit more tricky since there's name mangling involved; you'd have to wrap all the functions you want to call from Pascal code in 'extern "C" {}' blocks.

    Basically I compiled the C code to .o files, and in my Pascal code I put all the functions I needed calling as cdecl (since the calling conventions have to match) - but you can also do it the other way, use "alias" (or was it "name"?) in Pascal code to force a link-name for a function, and then define it as extern in the C code. Either way, later on one can either use {$LINK} in the Pascal code, or the -k command-line option to let the linker know it must include the .o file in the executable. Note that this process requires FPC to build the executable. Should you want to compile some Pascal code, and then build the final executable with gcc, things may not be so simple.

  4. #4
    In a company that I've been working with, this approach has been used for over 8 months already: most work is done on C++ side and then exported via simple DLL interface (flattened C-style methods) to Delphi. Generally C++ compilers produce much more efficient code (see (1) and (2)), so the performance is better than never and you have overall piece of mind that code is sufficiently future-proof. It seems that C++ community has grown massively since introduction of C++11 (and C++14, now C++17) and with large investments from big players like Google, Apple and Microsoft, it is not going anywhere any time soon.

  5. #5
    What Super Vegeta and LP said works, but only with C code, this is no classes nor objects. When people ask about C++ I always think in classes, and that's not very portable.
    No signature provided yet.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •