TGridOptions 上二进制表达式的无效操作数
Invalid operands to binary expression on TGridOptions
我最近从 C++ Builder XE8 升级到 Rad Studio 10 Seattle。我正在尝试使用新的 Clang 编译器,但我 运行 遇到了问题。
在自定义网格上 class 我有以下代码行:
__property Options = {default=TGridOption::AlternatingRowBackground << TGridOption::RowSelect};
这会导致编译器出现以下错误:
[CLANG Error] FmGridU.h(57): invalid operands to binary expression ('Fmx::Grid::TGridOption' and 'Fmx::Grid::TGridOption')
根据我在其他问题中读到的内容,我需要做一些事情,比如实现我自己的 <<
运算符。但是,我不确定我将如何去做。据我了解,当前代码是使用控制选项的标准方式。
新的 Clang 编译器有什么区别导致它抛出 Classic Boreland 编译器不会抛出的错误?如何实现 <<
运算符以允许我设置选项 属性?
编辑:
我已经按照 Remy 的建议更正了我的语法。
__property Options = {default = TGridOptions() << TGridOption::AlternatingRowBackground << TGridOption::RowSelect};
但是,现在我收到以下错误:
'expression is not an integral constant expression'
根据 this question,答案是将代码放在一个函数中。但是,由于我在头文件中声明了这个 属性,所以我不确定该怎么做。还有什么我想念的吗?
在经典编译器或新的 CLang 编译器中,这不是有效语法。 Options
是 TGridOptions
,它是 TGridOption
值的 Set<>
(即:typedef System::Set<TGridOption, TGridOption::AlternatingRowBackground, TGridOption::HeaderClick> TGridOptions;
)。您需要构造一个实际的 TGridOptions
对象,然后才能为其赋值,例如:
TGridOptions MyOptions = TGridOptions() << TGridOption::AlternatingRowBackground << TGridOption::RowSelect;
但是,您不能在 属性 声明中创建 Set<>
对象。
不过,您可以做的是指定一个数字常量来表示 Set<>
对象的二进制内容。在这种情况下,对于 TGridOptions
集合,TGridOption::AlternatingRowBackground
位于第 0 位,TGridOption::RowSelect
位于第 7 位,因此包含两个 TGridOption::AlternatingRowBackground
的集合的数值TGridOption::RowSelect
启用的是二进制 10000001
、十六进制 0x81
、十进制 129
,因此您可以这样声明 属性:
__property Options = {default = 0x81};
__property Options = {default = 129};
这在 Delphi 中比在 C++ 中更容易处理,因为 Delphi 允许您指定实际集合(Delphi 编译器在生成 C++ 时将其转换为数字常量.HPP 文件):
property Options default [TGridOption.AlternatingRowBackground, TGridOption.RowSelect];
在任何一种情况下,与任何其他 属性 一样,请确保您实际上在网格的构造函数中分配了相同的 TGridOptions
默认值以匹配 属性 声明,或者否则 属性 将无法正确流式传输 to/from 一个 DFM/FMX 资源。在这种情况下,您可以使用真正的 TGridOptions
对象来分配 属性 值:
__fastcall TMyGrid::TMyGrid(TComponent *AOwner)
: public TCustomGrid(AOwner)
{
Options = TGridOptions() << TGridOption::AlternatingRowBackground << TGridOption::RowSelect;
}
我最近从 C++ Builder XE8 升级到 Rad Studio 10 Seattle。我正在尝试使用新的 Clang 编译器,但我 运行 遇到了问题。
在自定义网格上 class 我有以下代码行:
__property Options = {default=TGridOption::AlternatingRowBackground << TGridOption::RowSelect};
这会导致编译器出现以下错误:
[CLANG Error] FmGridU.h(57): invalid operands to binary expression ('Fmx::Grid::TGridOption' and 'Fmx::Grid::TGridOption')
根据我在其他问题中读到的内容,我需要做一些事情,比如实现我自己的 <<
运算符。但是,我不确定我将如何去做。据我了解,当前代码是使用控制选项的标准方式。
新的 Clang 编译器有什么区别导致它抛出 Classic Boreland 编译器不会抛出的错误?如何实现 <<
运算符以允许我设置选项 属性?
编辑:
我已经按照 Remy 的建议更正了我的语法。
__property Options = {default = TGridOptions() << TGridOption::AlternatingRowBackground << TGridOption::RowSelect};
但是,现在我收到以下错误:
'expression is not an integral constant expression'
根据 this question,答案是将代码放在一个函数中。但是,由于我在头文件中声明了这个 属性,所以我不确定该怎么做。还有什么我想念的吗?
在经典编译器或新的 CLang 编译器中,这不是有效语法。 Options
是 TGridOptions
,它是 TGridOption
值的 Set<>
(即:typedef System::Set<TGridOption, TGridOption::AlternatingRowBackground, TGridOption::HeaderClick> TGridOptions;
)。您需要构造一个实际的 TGridOptions
对象,然后才能为其赋值,例如:
TGridOptions MyOptions = TGridOptions() << TGridOption::AlternatingRowBackground << TGridOption::RowSelect;
但是,您不能在 属性 声明中创建 Set<>
对象。
不过,您可以做的是指定一个数字常量来表示 Set<>
对象的二进制内容。在这种情况下,对于 TGridOptions
集合,TGridOption::AlternatingRowBackground
位于第 0 位,TGridOption::RowSelect
位于第 7 位,因此包含两个 TGridOption::AlternatingRowBackground
的集合的数值TGridOption::RowSelect
启用的是二进制 10000001
、十六进制 0x81
、十进制 129
,因此您可以这样声明 属性:
__property Options = {default = 0x81};
__property Options = {default = 129};
这在 Delphi 中比在 C++ 中更容易处理,因为 Delphi 允许您指定实际集合(Delphi 编译器在生成 C++ 时将其转换为数字常量.HPP 文件):
property Options default [TGridOption.AlternatingRowBackground, TGridOption.RowSelect];
在任何一种情况下,与任何其他 属性 一样,请确保您实际上在网格的构造函数中分配了相同的 TGridOptions
默认值以匹配 属性 声明,或者否则 属性 将无法正确流式传输 to/from 一个 DFM/FMX 资源。在这种情况下,您可以使用真正的 TGridOptions
对象来分配 属性 值:
__fastcall TMyGrid::TMyGrid(TComponent *AOwner)
: public TCustomGrid(AOwner)
{
Options = TGridOptions() << TGridOption::AlternatingRowBackground << TGridOption::RowSelect;
}