I have recently upgraded from C++ Builder XE8 to Rad Studio 10 Seattle. I am trying to use the new Clang compiler but I am running into an issue.
On a custom grid class I have the following line of code:
__property Options = {default=TGridOption::AlternatingRowBackground << TGridOption::RowSelect};
Which causes the following error from the compiler:
[CLANG Error] FmGridU.h(57): invalid operands to binary expression ('Fmx::Grid::TGridOption' and 'Fmx::Grid::TGridOption')
From what I have read in other questions, I need to do something like implement my own << operator. However, I am not exactly sure how I would go about doing this. From my understanding, the current code is the standard way to work with control options.
What is the difference with the new Clang compiler that causes it to thrown an error where the Classic Boreland compiler does not? How can I implement the << operator to allow me to set the options property?
Edit:
I have corrected my syntax as per Remy's suggestion.
__property Options = {default = TGridOptions() << TGridOption::AlternatingRowBackground << TGridOption::RowSelect};
However, now I get the following error:
'expression is not an integral constant expression'
According to this question the answer was to put the code inside of a function. However, since I am declaring this property in a header file, I am not sure how to do that. Is there something else I am missing?
That is not valid syntax, in either the classic compiler or the new CLang compiler.
Optionsis aTGridOptions, which is aSet<>ofTGridOptionvalues (ie:typedef System::Set<TGridOption, TGridOption::AlternatingRowBackground, TGridOption::HeaderClick> TGridOptions;). You need to construct an actualTGridOptionsobject before you can assign any values to it, eg:However, you cannot create a
Set<>object inside of a property declaration. What you can do, though, is specify a numeric constant that represents the binary content of aSet<>object. In this case, for aTGridOptionsset,TGridOption::AlternatingRowBackgroundis located at bit 0 andTGridOption::RowSelectis located at bit 7, thus the numeric value of the set that contains bothTGridOption::AlternatingRowBackgroundandTGridOption::RowSelectenabled is binary10000001, hex0x81, decimal129, thus you can declare the property like this:This is easier to handle in Delphi than in C++, as Delphi lets you specify the actual set (which the Delphi compiler translates to a numeric constant when generating a C++ .HPP file):
In either case, as with any other property, make sure that you are actually assigning the same
TGridOptionsdefault value in your grid's constructor to match the property declaration, or else the property will not stream to/from a DFM/FMX resource correctly. In this case, you can use a realTGridOptionsobject to assign the property value: