propertiesenumsc++builderc++builder-xe7

C++ (Builder XE7) enum type property misterious behaviour


I'm not an expert in C++ but need to update an old project to Embarcadero C++ Builder XE7.

This code does not compile (the fpFixed line):

#include <System.UITypes.hpp>
...
NewText->Font->Pitch = fpFixed;

Where Pitch is:

__property System::Uitypes::TFontPitch Pitch = {read=GetPitch, write=SetPitch, default=0};
void __fastcall SetPitch(const System::Uitypes::TFontPitch Value);

and

enum class DECLSPEC_DENUM TFontPitch : unsigned char { fpDefault, fpVariable, fpFixed };

Error: "E2451 Undefined symbol 'fpFixed'"

Another two attempts:

NewText->Font->Pitch = TFontPitch.fpFixed;
NewText->Font->Pitch = System::Uitypes::TFontPitch.fpFixed;

Error for both: E2108 Improper use of typedef 'TFontPitch'

But this - strangely - compiles, with no warning:

System::Uitypes::TFontPitch( fpFixed );   // yes,no assignments here just an unused value
NewText->Font->Pitch = fpFixed;

What is the explanation of this and am I doing something wrong here? Just came to this "solution" by trial and error.


Solution

  • NewText->Font->Pitch = TFontPitch.fpFixed;
    NewText->Font->Pitch = System::Uitypes::TFontPitch.fpFixed;

    You were on the right track with this, but you used the wrong syntax. Use :: instead of .:

    NewText->Font->Pitch = TFontPitch::fpFixed;
    NewText->Font->Pitch = System::Uitypes::TFontPitch::fpFixed;
    

    This is documented in Embarcadero's DocWiki:

    Strongly Typed Enums (C++0x)