Skip to content

Enumeration Enhancements

Xojo 2021r2 introduces a couple of enhancements to enumerations in Xojo. The enumeration editor now shows a preview of what the value will be so there’s no more guessing or counting.

Example of Enumeration with default values showing

In addition, we’ve added a new Binary option which allows you to automatically create sets that aren’t mutually exclusive. That is, the values of the elements are automatically powers of two and can have binary operations applied to them:

Example of Binary Enumeration default values

This new feature comes with the requirement that they be placed inside a Module because they’re rendered into your project as a Class. The reason for this is that these classes automatically have some helper methods on them to make working with the binary data easier.

  • A Constructor which takes an Integer:
    Var x as New MyEnum(3) // MyEnum.George, MyEnum.John
  • Automatic conversion to and from Integer:
    Var x as Integer = MyEnum.Ringo // x = 4
  • Binary operations And, Or and Xor:
    Var x as MyEnum = MyEnum.Paul Or MyEnum.Mary // x has a value of 40
  • Equality operations so you can compare the internal value of one instance to another:
    Var x as MyEnum = MyEnum.Paul
    Var y as MyEnum = MyEnum.Ringo
    If x = y Then

  • Contains helper method:
    If x.Contains(MyEnum.Peter) Then
  • A Read-Only Value property so you can see the internal value in the debugger

Just like regular Enumerations, the editor also allows you to explicitly specify the value of an element:

This is so instead of having to write:
Var x as MyEnum = MyEnum.George Or MyEnum.John Or MyEnum.Ringo Or MyEnum.Paul

You can simply write:
Var x as MyEnum = MyEnum.TheBeatles

We hope that you’ll enjoy this feature as much as we do!