[fpc-pascal] Enum RTTI

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Nov 5 10:54:05 CET 2009


On 05 Nov 2009, at 09:32, Wimpie Nortje wrote:

> Is there any way to achieve the following easily:
> 1) for enum_first to enum_last do....

No, because succ/pred are not defined for sparse enums.

> 2) NumberOfItems(enum)

No. Even typeinfo() doesn't work for sparse enums.

> I very often have enums for which I want string descriptions.

As of FPC 2.4.0, you will be able to use

var
   s: string; { any kind of string will work
begin
   writestr(s,enumvar);
end;

And afterwards 's' will contain the string representation of enumvar.  
In general, writestr is identical to the regular "write" procedure,  
except that it stores its output in a string (which you have to pass  
as first parameter). A similar "readstr" procedure will also be  
available.


Jonas



More information about the fpc-pascal mailing list