Return name of enumeration constant.
Source position: typinfo.pp line 1316
function GetEnumName( |
TypeInfo: PTypeInfo; |
Value: Integer |
):string; |
GetEnumName scans the type information for the enumeration type described by TypeInfo and returns the name of the enumeration constant for the element with ordinal value equal to Value.
If Value is out of range, the first element of the enumeration type is returned. The result is returned in the case that was used in the declaration. (In earlier versions of FPC, the name was lowercased).
This can be used in combination with GetOrdProp to stream a property of an enumerated type.
No check is done to determine whether TypeInfo really points to the type information for an enumerated type.
|
Get the value of an ordinal property. |
|
|
Get ordinal value for enumerated type by name. |
program example9; { This program demonstrates the GetEnumName, GetEnumValue functions } {$mode objfpc} uses rttiobj,typinfo; Var O : TMyTestObject; TI : PTypeInfo; begin O:=TMyTestObject.Create; TI:=GetPropInfo(O,'MyEnumField')^.PropType; Writeln('GetEnumName : ',GetEnumName(TI,Ord(O.MyEnumField))); Writeln('GetEnumValue(mefirst) : ',GetEnumName(TI,GetEnumValue(TI,'mefirst'))); O.Free; end.