Jump to content
dmitrybv

[bcc32c Error] hpp: expected unqualified-id

Recommended Posts

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.

 

image.thumb.png.0c7947ab80c3fdda8fb21fc961986a07.png

Edited by dmitrybv

Share this post


Link to post

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 by Remy Lebeau

Share this post


Link to post
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 by dmitrybv

Share this post


Link to post
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 by Remy Lebeau
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×