I want to use the library "VCL Style Utils" in Embarcadero C++Builder 10.2 Tokyo.
So I created a new project and added:
Vcl.Styles.Utils.Graphics.pas
Vcl.Styles.Utils.Menus.pas
Vcl.Styles.Utils.SysControls.pas
Vcl.Styles.Utils.SysStyleHook.pas
The build is successful and generates .hpp
files for these .pas
files.
Then I create another project and include the .hpp
files generated.
But when building I get this error:
[bcc32 Error] Vcl.Styles.Utils.Menus.hpp(164): E2040 Declaration terminated incorrectly.
Here are lines 163 and 164 of Vcl.Styles.Utils.Menus.hpp :
static const System::Word MN_SETHMENU = System::Word(0x1e0);
static const System::Word MN_GETHMENU = System::Word(0x1e1);
Why are these declarations incorrect ?
There are likely pre-existing #define
statements for MN_SETHMENU
and MN_GETHMENU
in another C/C++ header file that is in scope, eg:
#define MN_SETHMENU 0x01E0
#define MN_GETHMENU 0x01E1
If so, that would interfere with the declarations generated in Vcl.Styles.Utils.Menus.hpp
, making the compiler see them as:
static const System::Word 0x01E0 = System::Word(0x1e0);
static const System::Word 0x01E1 = System::Word(0x1e1);
Which is clearly wrong, and hence the errors.
In Vcl.Styles.Utils.Menus.pas
(and in .pas
files in general), the declarations for MN_SETHMENU
and MN_GETHMENU
(and anything else that is already pre-defined in C/C++ headers) need to be marked with the {$EXTERNALSYM ...}
directive so they are not re-declared in the generated .hpp
file, eg:
{$EXTERNALSYM MN_SETHMENU} // <-- add this
MN_SETHMENU = $01E0;
{$EXTERNALSYM MN_GETHMENU} // <-- add this
MN_GETHMENU = $01E1;
If necessary, use the {$HPPEMIT '...'}
directive to add suitable #include
statements to the generated .hpp
file so it can pull in other C/C++ header files as needed, eg:
{$HPPEMIT '#include <OtherFile.h>'}