Enums

From The Oxygene Language Wiki
Jump to: navigation, search

This is a Language topic about Oxygene
 

Language Topics Introduction | Structured Overview | Grammar | Keywords | Functions



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:

  • Byte
  • SByte
  • Int16
  • Int32
  • Int64
  • UInt16
  • UInt32
  • UInt64
  • Char


See Also

Personal tools
Namespaces

Variants
Actions
Navigation
Getting Started
Sections
If you know
More
Toolbox