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

Frank Church vfclists at gmail.com
Mon Aug 30 13:43:50 CEST 2010


On 30 August 2010 11:37, Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:

> 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;
>
>
Is there a way to pass the enum so that the type will not matter, so that
the type can be determined at runtime, so that it is not necessary to create
a new function for every type?


>
> GetEnumName is defined in 'typinfo' unit.
>
>
> Regards,
>  - Graeme -
>
> --
> fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
> http://opensoft.homeip.net/fpgui/
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



-- 
Frank Church

=======================
http://devblog.brahmancreations.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100830/4c214903/attachment.html>


More information about the fpc-pascal mailing list