Enums

From The Oxygene Language Wiki

Jump to:navigation, search

This is a Language topic
Feel free to add your notes to this topic below.



Enums are simple, integer-based types that can be used as an enumeration, where an enum has 1 value out of a list, or a bitflag, where it has several bits defining its value.

An enum is a special type and is restricted to only have possible values defined as constants on the enum.

The syntax used to define and use enum is:

type
  MyEnum = enum (a,b,c, d = 255);

var
  r: MyEnum;
begin
  r := MyEnum.b;
...
  if r = MyEnum.c then


The members of an enum are automatically assigned a value if none is given, starting at 0, increasing 1 from the previous member. When using the flags keyword instead of enum, a special kind of enum can be defined. Here, the members increase by finding the next in the Power (2, n) sequence.

type
  MyFlags = flags(a, b, c);
begin
  r := MyFlags.a;
  r := r + MyFlags.c;
  if MyFlags.b in r then ...

Typed Enums

An extended syntax is provided to assign enums a specific integer type for internal storage by suffixing of type" to the enum declaration:

type
  x = enum (a,b,c) of byte;
  y = (a,b,c) of byte;

All the built-in integral types are supported:


See Also

Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox