[fpc-pascal] Enum RTTI
jonas.maebe at elis.ugent.be
Thu Nov 5 11:27:46 CET 2009
On 05 Nov 2009, at 11:10, Wolfram Kläger wrote:
> maybe you want to try:
> // implementation
> function Str(const AEnum : TEnum) : String; overload;
> Result := GetEnumName(TypeInfo(TEnum), ord(AEnum));
> I usually declare one such overload per enum type. If you are using
> sysutils.Str, you have to avoid conflicts by chosing a different
> function name, e.g. EnumStr.
Actually, as of FPC 2.4.0 str() is also supported for enum types (so
in this case you don't need the writestr I mentioned earlier). It
crashes if you pass an invalid enum value though, and there are next
to no tests for this functionality so it may also contain other bugs.
More information about the fpc-pascal