Delphi. Enum and strings

working approach

Result := System.TypInfo.GetEnumName (TypeInfo (TEnum), Ord (FEnum)));

other approaches

TEnum = (enOne, enTwo, enThree, enFour, enFive, enSix);

// 1
case Self of
    enOne   : Result := 'One';

// 2
const cOne: strig = 'One';
...
case Self of
    enOne   : Result := cOne;

// 3
const cEnumStr: array[TEnum] of string = ('One', 'Two', 'Three', 'Four', 'Five', 'Six');
...
Result := cEnumStr[Self];

Source

This entry was posted in Без рубрики. Bookmark the permalink.