Recent

Author Topic: Are there any good C++ to Delphi translators available?  (Read 9660 times)

sarason

  • Jr. Member
  • **
  • Posts: 77
Are there any good C++ to Delphi translators available?
« on: April 24, 2014, 05:08:29 am »
Are there any good C++ to Delphi translators available?

I have used openc2pas. Well not very useful!
C2PAS32. The best I have found so far
AL Guns CtoPas. Pretty Good

Not to mention Bob Swarts C++ to Pascal Header Convertor,
Which I don't mention as I have never got it to work on any header file. :D

Any others OT or would some fine gentlemen wish to join me in writing something.(More of a dream as I have no spare time for any projects at the moment)

regards sarason

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Are there any good C++ to Delphi translators available?
« Reply #1 on: April 24, 2014, 06:35:49 am »
IMHO it depends on what C++ part you want to translate to Delphi.


I can confirm that Dr Bob C to Pas Header convertor work perfectly as I expect.
This way, it only translate the C header (*.h) for later used as wrapper/binding to that C library (*.dll)
I can give you a prove. This file is tranlated to pas:
https://github.com/x2nie/Embroidermodder/blob/master/experimental/delphi/binding/libembroidery.pas
translated from several of C header files listed here:
https://github.com/x2nie/Embroidermodder/tree/master/libembroidery


If you failed to translate from C/C++ to pas, you can't hate the weapon you are using.
In my experience, there is no one step for solving all cases of translation. You will always
need to modify some code to get pascal code properly.


Let say you only need to translate the header C. It's not really easy IMHO:


The usual problem is pointer in C is similar as C's array.
When in pascal, that two kind is very different from the beginning of how it declared.
The other common problem is how to distinct that C array to be keep as array or to be a "var" parameters (in/out) in pascal function.


No? not only C header code?
You might want to translate the C/C++ code to pascal/Delphi...
I've experience doing this. I've progress in a project translating the whole C++ code to pascal.
This way, I did manually line by line, function by function, everything manually. It is idot way, but At least I able to control the progress of such features of development.
But I still always worry about the result, since both has different approach specially in memory management.
I cant make sure whether the translated pascal code has had identic result according the original program written in C/C++ one.


Another better approach (rather than reinvent the wheel), I recommend you to use SWIG.
It is widely used to translate C/C++ code to Python and vise-versa from Python to C.
But SWIG is not limited to C, it seem able to translate from/to almost nowadays programming language, except Delphi.
Why?
Why there is pascal doesn't supported yet by SWIG?
I think only idiot people want to do anything alone. Meaning Pascal language has been too close/near to C or C++ code,
I think pascal people don't require to translate all the code from C to Pas
I think pascal only need to know the generic part of C/C++ code to play with the rest C code.
Meaning, pascal only requires header part, not the whole code to run C program.




If we can do something easier, why we have to make something harder?


What do you think?


PS:
 Swig repository : https://github.com/swig/swig
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

sarason

  • Jr. Member
  • **
  • Posts: 77
Re: Are there any good C++ to Delphi translators available?
« Reply #2 on: April 24, 2014, 09:04:14 am »
I had forgotten about SWIG, IIRC there was a plugin for Delphi somewhere on the web.
I had a quick read on the SWIG sit you posted, it appears to only be a header convertor tool, Is it or does it also do the body of the code.
I wasn't trying to hate the tool (DrBobs Header convertor) but on any of the DLL's Itried to make work it never did, since time was pressing I did those DLL's by hand.

The one thing that all the tools I used had in common is they did little or no work on correcting function/procedure calls, and this necessitated an awful lot of typing on my part.

I get the issue with C arrays especially when converting C strings to the equivalent in pascal or should it be a pascal string, ansichar. etc.
and then what happens in the following code, that uses the said strings or then passes them into a function, and on it goes.

The reason I asked the question is that I do a lot of translating in my work, in both directions as it is good to have only one language in each application you work on. There are real problems using DLL's passing Complex data structures through a DLL from Pascal to C++ and vice versa. Most examples you would ever see on the web only ever deal with simple variables.
But to give an example I have an old data structure in C++ that is called from a Pascal application with about 50 files defining the structure it involves, two platforms Mac and PC, formats over about 20 versions, code can be read by both platforms, Fonts are convertible across both for similar look, It compiles on Borland C++, Macintosh Programmers Workshop (System 7), It has been bought forward to RAD2007, It has compression builtin, Endianess taken care of, etc.  No Type is simple, everything is defined down to the metal.

There is a fantastic tool for going from C to Pascal. Delphi2Cpp. Its just a shame there isn't a useful a tool going in the right direction!

sarason

 

TinyPortal © 2005-2018