[fpc-pascal] How can you convert an enum value to string?

Graeme Geldenhuys graemeg.lists at gmail.com
Mon Aug 30 12:37:02 CEST 2010


Op 2010-08-30 12:30, Frank Church het geskryf:
> Is there a subroutine that can convert an enum value to a strings, so
> that I can do something like ShowMessage(EnumToStr(enumValue))?


eg:

function ObjectStateToString(AObjectState : TPerObjectState): string;
begin
  result := GetEnumName(TypeInfo(TPerObjectState),
                         Ord(AObjectState));
end;


GetEnumName is defined in 'typinfo' unit.


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/




More information about the fpc-pascal mailing list