How to start

Top  Previous  Next

You will obtain good C++ translations of your Delphi code only if the correct settings are selected in the Translation Options dialog, which can be opened using 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 distinction is between C++Builder and all other C++ compilers.

 

C++Builder provides its own C++ version of the Delphi RTL/VCL, and Aurora2Cpp attempts to optimize the generated code to work together with these libraries as smoothly as possible.

 

Therefore, depending on the selected compiler, an appropriate string type should also be chosen. C++Builder provides classes such as AnsiString and WideString, which are very similar to the original Delphi string types.

 

For other compilers, it is generally recommended to use std::string and std::wstring instead, unless you intend to implement your own Delphi-like string classes.

 

 

 

2. Choosing the Correct RTL/VCL Source:

 

 

Delphi2Cpp must know the types and signatures of procedures and functions used in your Delphi source code in order to generate correct C++ translations.

 

This is straightforward for your own source code. You simply need to configure the paths to your source files in the options dialog.

 

However, every Delphi program implicitly uses the System unit, and most Delphi applications also depend on the SysUtils unit. Pre-translated C++ versions of these units are included with the Delphi2Cpp installation. The same folder also contains Pascal files with the interface sections of these units.

 

If your code does not depend on additional RTL/VCL units, you will usually obtain the best translation results by selecting the path to these Pascal interface files as the search path for the files not to convert.

 

In most real-world projects, however, the code depends on additional units from the Delphi RTL/VCL. If you are using Delphi2Cpp for the first time and simply want to obtain initial translation results quickly, you may use the original Delphi RTL/VCL source directories as the search path for files that should not be converted.

 

Unfortunately, the original Delphi source code itself contains a number of inconsistencies and special cases. Therefore, for long-term use it is recommended that you prepare a copy of Embarcadero's code sources for use with Delphi2Cpp.

 

If you use the original Delphi RTL/VCL sources, you should also use an extended System.pas. This file corrects and supplements the original System.pas.

 

 

3. Setting the Correct Conditional Definitions

 

 

Even if you have selected the correct search paths for the Delphi RTL/VCL, your code may still not be translated correctly unless the required conditional definitions are set properly.

 

By default, MSWINDOWS is defined. If this were not the case, even the original SysUtils.pas could not be parsed correctly, because code such as the following would become invalid:

 

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

        {$IFDEF LINUX} tlbsLF {$ENDIF}

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

 

 

 

4. Preparing the RTL/VCL Code

 

It may be necessary to define substitutions for some ampersand-expressions. Unfortunately, the RTL/VCL source code also contains flaws that must be corrected before it can be used reliably.

 

5. Creating a Dummy Application or Performing a Complete Translation

 

Normally, Delphi2Cpp performs a complete translation of the selected project.

 

However, if your source code is incomplete or not yet fully compilable, you may choose to create a dummy application first.

 

 

6. Starting the Translation

 

 

After you have set your translation options you can save them by the button ProjectSaveAs

Next, open the first file to translate using the button FileOpen.

Start the translation by clicking the button Arrow_r.

 

As soon as the translation has finished, the generated C++ header file and the C++ source code are displayed in the windows on the right side of the application.

 

The content shown on the left side may also change. In this case, the preprocessed Delphi code is displayed there.

 

You can save the translated code using the button FileSaveAs.

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content