Probably would be best if Xojo had a flag on the enum to specify it as “Flags” (could be attribute), and then let the compiler say the Or is ok when it is flags.
(Similar how C# does it they just put Attribute on it to tell the compiler its flags, keeping the Enum strict in other cases)
Well let us hope they are listening. There is no need for Xojo to be bad for no reason when it is small thing like this that at same time makes it so bad. !
[quote=425792:@Björn Eiríksson]Is there really no way to use Enum as bitwise flags others than doing cumbersome forced conversions to and from integer?
Like this works:
Dim a as Test = Test(Integer(Test.x) or Integer(Test.y))
While this gets rejected by the compiler:
Dim a as Test = Test.x or Test.y
(Test is Integer Enum that Defines x = 1 and y = 2)[/quote]
If Test defines X and Y then this line results in a value that is not one of the enumerated values
Dim a As Test = Test.x Or Test.y
so the result should be an integer - not a “Test”
Enums simply don’t have several operators defined Or, And, Xor, addRight AddLeft, etc.
I would say…not since thats basically same as doing Constants on a class.
But with constants you loose the typedefinition which you want to be still strongly typed even if you can and will bitmask it, so the signature of a method that takes in the Bitmask is something as myEnum and not something as Integer. That is the whole point of flags and bitmasks.