Enum type

From Lazarus wiki
Revision as of 12:57, 14 February 2020 by Trev (talk | contribs) (English translation of German page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

English (en)


Back to data types.


Range

  • with 0 .. 255 characters, the data type is automatically Byte
  • with 255 .. 65,535 characters, the data type is automatically Word
  • over 65,535 characters, the data type is automatically Longword

Memory requirement

  • depends on the data type and the number of elements.

Properties

The data type Enum Type is an enumeration of unsigned constants.

In addition, the unsigned integer data type to be used can be specified for the data type using a switch.

  • at 0 .. 255 characters the switch for the byte data type:
    • {$Z1} or {$ PACKENUM 1}
  • at 255 .. 65535 characters the switch for the Word data type:
    • {$Z2} or {$ PACKENUM 2}
  • at 65535 .. 4294967295 characters the switch for the LongWord data type:
    • {$Z4} or {$ PACKENUM 4}

The values ​​of the enumeration always increase by 1 to the next element.

Examples

Examples of declaring the Enum data type

The values ​​of the enumeration start at 0 by default:

  Type
   {$PACKENUM 2}
   LargeEnum = (zero, one, two);

By default, the values ​​of the enumeration start at 0, unless the enumeration is assigned a different starting value. Then the count starts with the assigned initial value.

  Type
   {$PACKENUM 4}
   SmallEnum = (Six := 6, Seven, Eight);

If a higher value is assigned to an element in the middle of the enumeration, counting continues from this value.

  Type
   {$ PACKENUM 1}
   MiddleEnum = (zero, ten := 10, eleven, twelve);

Explicit use of the byte data type for the enumeration.

  Type
   byte = (zero, one, two);

Examples of assigning the Enum data type

 var 
   S : SmallEnum;
   M : MiddleEnum;
   L : LargeEnum;

Examples for the conversion of the data type Enum

  Application.MessageBox(PChar(IntToStr(Qword(Ord(Six)))), 'Conversion' , MB_OK);
  Application.MessageBox(PChar(IntToStr(Qword(Ord(p.Six)))), 'Conversion' , MB_OK);