[Overview][Constants][Types][Classes][Procedures and functions] Reference for unit 'typinfo' (#rtl)

GetEnumName

Return name of enumeration constant.

Declaration

Source position: typinfo.pp line 275

function GetEnumName(

  TypeInfo: PTypeInfo;

  Value: Integer

):String;

Description

GetEnumNamescans the type information for the enumeration type described by TypeInfoand returns the name of the enumeration constant for the element with ordinal value equal to Value.

If Valueis out of range, the first element of the enumeration type is returned. The result is lowercased, but this may change in the future.

This can be used in combination with GetOrdPropto stream a property of an enumerated type.

Errors

No check is done to determine whether TypeInforeally points to the type information for an enumerated type.

See also

GetOrdProp

  

Get the value of an ordinal property

GetEnumValue

  

Get ordinal value for enumerated type by name

Example

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.