In Greg O’Lone’s recent blog posting, he discusses the new enumeration enhancements in Xojo 2021r2. One of the enhancements is the ability to use the enumeration as a Constructor which takes an Integer.
I have attempted to duplicate this new feature with the following code:
Enum SomeEnum // placed inside a Module
Foo = 0
Bar = 1
Baz = 2
Var x as New SomeEnum(2) // Using the enumeration as a Constructor which takes an Integer
If x = SomeEnum.Baz then
// x = SomeEnum.Baz
End if
But I get the following error: “Cannot create an instance of enum Module1.SomeEnum with New because it is not a class.
Var x as New SomeEnum(2)”.
I am using the new Xojo version Xojo 2021r2.
I am sure I am doing something wrong here. Can anyone help?
I just tried this myself thinking that it only applied to the new Binary enums, but I get an error that the constructor is protected when I try that. I have a message in to @Greg_O_Lone
OK, it looks like the addition of a constructor in the blog post was an error. The constructor is not exposed, so you would use something like the following to cast an integer to an enum value: