dmitrybv 3 Posted Tuesday at 03:36 PM (edited) Hello I have a pas unit EhLibFmx.ToolControls.pas in my package which contains the following statement const { Scroll Bar Constants } SB_HORZ = 0; SB_VERT = 1; SB_CTL = 2; SB_BOTH = 3; When I try to compile a C++ project which uses this hpp file based on this unit, bcc32c gives a compilation error: [bcc32c Error] EhLibFmx.ToolControls.hpp(626): expected unqualified-id On the line static _DELPHI_CONST System::Int8 SB_HORZ = System::Int8(0x0); I can't figure out what the error is. And how to make the correction correctly. After all, hpp is generated automatically. Edited Tuesday at 03:37 PM by dmitrybv Share this post Link to post
Remy Lebeau 1436 Posted Tuesday at 04:34 PM (edited) Those constants are already defined in the Win32 SDK headers (specifically, in winuser.h) using #define macros: /* * Scroll Bar Constants */ #define SB_HORZ 0 #define SB_VERT 1 #define SB_CTL 2 #define SB_BOTH 3 That will interfere with any C++ code that tries to use your constants for ANY reason (including the declarations!). For example: static _DELPHI_CONST System::Int8 SB_HORZ = System::Int8(0x0); This will be misinterpreted by the C++ compiler as the following instead, hence the error you are getting: static _DELPHI_CONST System::Int8 0 = System::Int8(0x0); To avoid this, don't redeclare Win32 constants in C++. Declare your constants in your Pascal unit as {$EXTERNALSYM} (or {$NODEFINE}) so they are omitted in your generated HPP file: const { Scroll Bar Constants } {$EXTERNALSYM SB_HORZ} SB_HORZ = 0; {$EXTERNALSYM SB_VERT} SB_VERT = 1; {$EXTERNALSYM SB_CTL} SB_CTL = 2; {$EXTERNALSYM SB_BOTH} SB_BOTH = 3; Alternatively, change your Pascal unit to use the constants that are already declared in the Winapi.Windows unit, which are EXTERNALSYM'ed (just be sure to {$IFDEF} that unit since you appear to be coding for FMX). Edited Tuesday at 04:50 PM by Remy Lebeau Share this post Link to post
dmitrybv 3 Posted Tuesday at 04:45 PM (edited) 7 minutes ago, Remy Lebeau said: Those constants are already defined in the Win32 SDK (specifically, in winuser.h) using #define macros, which interfers with your C++ code. You need to declare your constants as {$EXTERNALSYM} in your Pascal code. What about namespace The constants are declared inside namespace namespace Ehlibfmx { namespace Toolcontrols { static _DELPHI_CONST System::Int8 SB_HORZ = System::Int8(0x0); } } Doesn't this isolate them from interfering with external identifiers? Edited Tuesday at 04:46 PM by dmitrybv Share this post Link to post
Remy Lebeau 1436 Posted Tuesday at 04:52 PM (edited) 5 minutes ago, dmitrybv said: What about namespace The constants are declared inside namespace Doesn't this isolate them from interfering with external identifiers? The Win32 constants are being declared in the SDK using #define statements, which are parsed during the preprocess stage, and are just straight text replacements. As such, they don't respect C++ namespaces at the compile stage, as the code has already been modified by the preprocessor before the compiler sees it. Thus, the compiler will not see this code, as you expect: namespace Ehlibfmx { namespace Toolcontrols { static _DELPHI_CONST System::Int8 SB_HORZ = System::Int8(0x0); } } But will see this code instead: namespace Ehlibfmx { namespace Toolcontrols { static _DELPHI_CONST System::Int8 0 = System::Int8(0x0); } } Which is a syntax error in the C++ language. Edited Tuesday at 04:56 PM by Remy Lebeau 1 Share this post Link to post