Resource Strings
Go Up to Support for Object Pascal Data Types and Language Concepts
If you have code in a Delphi unit that uses resource strings, the Delphi compiler (DCC32) generates a global variable and a corresponding preprocessor macro for each resource string when it generates the header file. The macros are used to automatically load the resource strings, and are intended to be used in your C++ code in all places where the resource string is referenced. For example, the resourcestring section in the Delphi code could contain:
unit MyUnit;
interface
resourcestring
Warning = 'Be careful when accessing string resources.';
implementation
begin
end.
The corresponding code generated by the Delphi compiler for C++Builder would be
extern PACKAGE System::Resource ResourceString _Warning;
#define Myunit_Warning System::LoadResourceString(&Myunit::_Warning)
- Notes:
- Unit names are normalized in C++, as C++ is a case-sensitive language. That is why the unit name, "MyUnit", becomes "Myunit" in C++.
- "_Warning", as any other instance of ResourceString generated by the Delphi compiler, is declared within the "Myunit" namespace, so you must access it as
Myunit::_Warning
. - The define line lets you use the exported Delphi resource string as "Myunit_Warning" without having to explicitly call LoadResourceString.
See Also
- Support for Object Pascal Data Types and Language Concepts
- Resource Strings in the Delphi Language Guide
- Output - C/C++
- LoadResourceString function
- ResourceString class
- ResourceString (C++) code example