Delphi Programming

GetEnumValue Routine

2,918pages on
this wiki
This page is intended as a supplement to the official documentation on Delphi programming. CodeGear is in the process of putting the Delphi documentation on the Web. Once they have done so, this page will link to the relevant page in the official documentation.
This article is a stub.
Please help enhance the Delphi Programming Wiki by expanding it.
see the VCL Documentation Guidelines for an overview on doc pages



GetEnumValue is a function to get the ordinal value of an enumeration value.

The first parameter (TypeInfo: PTypeInfo) is a pointer to the typeinfo of the enumeration type.

The second parameter (Name: string) is the enumeration value name in the form of a string.

The result is the ordinal value of the enumeration value.

Technical CommentsEdit

Be aware that Typeinfo will be lost when the enumeration is given different ordinal values. With the next enumeration example it's not possible to use GetEnumValue and will result in 'E2134 Type 'TTestType' has no type info'

  TTestType = (ttTest1 = 2, ttTest2 = 4, ttTestUnknown = 6);


  TTestType = (ttTest1 {0}, ttTest2 {1}, ttTestUnknown {2});
ShowMessage(IntToStr(GetEnumValue(TypeInfo(TTestType), 'ttTestUnknown'))); //will show 2

See AlsoEdit

User Comments/TipsEdit

(Please leave your name with your comment.)

Around Wikia's network

Random Wiki