delphicastingintegerpascalenumeration

Cast Enumeration Value to Integer in Delphi


Is it possible to cast/convert an Enumeration Value to an Integer in the Delphi Programming Language?

If yes, then how?


Solution

  • This is called out explicitly at the documentation for enumerated types:

    Several predefined functions operate on ordinal values and type identifiers. The most important of them are summarized below.

    | Function |                       Parameter                       |                      Return value | Remarks                                           |
    |----------|:-----------------------------------------------------:|----------------------------------:|---------------------------------------------------|
    | Ord      |                   Ordinal expression                  |  Ordinality of expression's value | Does not take Int64 arguments.                    |
    | Pred     |                   Ordinal expression                  | Predecessor of expression's value |                                                   |
    | Succ     |                   Ordinal expression                  |   Successor of expression's value |                                                   |
    | High     | Ordinal type identifier or   variable of ordinal type | Highest value in type             | Also operates on short-string   types and arrays. |
    | Low      | Ordinal type identifier or   variable of ordinal type | Lowest value in type              | Also operates on short-string   types and arrays. |