C++ (Builder XE7) 枚举类型 属性 奇怪的行为

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

我不是 C++ 专家,但需要将旧项目更新到 Embarcadero C++ Builder XE7。

此代码无法编译(fpFixed 行):

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

其中 Pitch 是:

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

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

错误:"E2451 Undefined symbol 'fpFixed'"

另外两次尝试:

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

两者都出错:E2108 typedef 使用不当'TFontPitch'

但是这个 - 奇怪地 - 编译,没有警告:

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

这是什么解释,我是不是做错了什么?刚刚通过反复试验得出 "solution"。

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

你在这方面走在了正确的轨道上,但你使用了错误的语法。使用 :: 而不是 .:

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

这在 Embarcadero 的 DocWiki 中有记录:

Strongly Typed Enums (C++0x)