Resource strings

Top  Previous  Next

What is translated > Resource strings

 

Delphi compiler has built-in support for resource strings whereas in C++ you have to edit resource files manually and insert them into your project. If a project is prepared in that manner the resource strings can be loaded either by the functions LoadStr and FmtLoadStr of the unit Sysutils or by the function LoadResourceString in the System unit. The latter function is used in C++Builder, when it includes Delphi files with resource strings. The first approach of Delphi2Cpp was, to use this method too. But it has proved to be too complicated, because it needs instances of ResourceString structures with a pointers to the module handles of the modules, where the strings are included.

A simplified approach is made by Delphi2Cpp, which will lookup resource strings in the current module only and which uses default strings in the case, that no resource files are added to the project.

 

If the Delphi unit Test contains the section:

resourcestring

SIndexError  = 'Index out of bounds: %d';

 

then the translated code will contain the definition:

 

#define Test_SIndexError d2c_LoadResourceString( (int)  "Index out of bounds: %d" )

 

At positions, where resource strings are used, they are now substituted be the according macro.

 

Exception ( SIndexError )

->

Exception ( Test_SIndexError )

 

The function d2c_LoadResourceString creates a temporary ResourceString structure, which is passed to the Delphi function LoadResourceString. If a real resource file is created and used, d2c_LoadResourceString can be called with the identifier which is assigned to the strind in the resource.

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content