How to start

Top  Previous  Next

 

You will get good C++ translations of your Delphi code only, if you make the correct settings in dialog for the translation options, which can be shown by the button  OptionsProject . There are two main decisions to make.

 

 

1. C++ Builder or other compiler

 

 

The translation result depends on the C++ compiler you use. The main difference is between the C++Builder and all other compilers. C++-Builder has it's own C++ version of the Delphi RTL/VCL and Delphi2Cpp tries to optimize the translated code to work together with these libraries. So, depending on the used compiler the desired string type also has to be be chosen. C++ Builder has classes for AnsiStrings and WideStrings, which are very similar to the original Delphi types. For other compilers it is recommended to use std::string and std::wstring instead, if you don't want to write your own Delphi like string classes. You further have to decide, whether you want C++ code for a unicode/widestring application or for a classic application, based on single byte characters.

 

 

2. Choosing the correct source for the RTL/VCL:

 

 

Delphi2Cpp has to know the types and signatures of procedures and  functions in your Delphi source code to make a correct translation. That's no problem as far as these information stems from your own source code. You simply have to set the paths to your source code at the according place in the options dialog.

But all Delphi code implicitly also includes the System unit and most Delphi code uses at least the Sysutils unit too. Already translated C++ code for these both units is part of the Delphi2Cpp installation. In the same folder there are pas-files with the Delphi interface parts of these units. If no other units from the Delphi RTL/VCL are used in your code, you will get the best translation results, if you select the path to these pas-files as search path for the files not to convert. Mostly your code will depend on more units of the Delphi RTL/VCL. In this case you should select the paths to the original Delphi RTL/VCL. If there is more than one edition of the Delphi RTL/VCL installed on your computer, than please choose the oldest version (beginning from Delphi 4), because Delphi2Cpp might have difficulties to parse more recent Delphi language extensions.

If you make use of the original Delphi RTL/VCL, you should use also an "extended System.pas". This file corrects and completes the original "System.pas".

 

 

3. Setting the correct definitions

 

 

If you have selected the search paths to the Delphi RTL/VCL, your code still might not be translated correctly, if you haven't set the necessary definitions.

As default MSWINDOWS is.defined. If that would not be the case, even the original Sysutils.pas cannot be parsed, because e.g. the following code, would not be valid:

 

function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle =

        {$IFDEF LINUX} tlbsLF {$ENDIF}

        {$IFDEF MSWINDOWS} tlbsCRLF {$ENDIF}): string;

 

 

 

4. Starting the translation

 

 

After you have set your translation options you can save them by the button ProjectSaveAs and open the first file to to translate with the button FileOpen.. The source file is shown in the left window of the user interface. You can start the translation with the button Arrow_r. As soon as it is finished the C++ header and the C++ source code are shown in the windows on the right side of the application. Also the content on the left side might have changed: now the preprocessed Delphi code is shown there. You can save the translated code by the button FileSaveAs.

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content