[fpc-pascal] Enum RTTI

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Nov 5 11:26:19 CET 2009


On 05 Nov 2009, at 11:16, Wimpie Nortje wrote:

>>> 1) for enum_first to enum_last do....
>> Is there any way to achieve the following easily:
>>
>> No, because succ/pred are not defined for sparse enums.
>>
>>> 2) NumberOfItems(enum)
>>
>> No. Even typeinfo() doesn't work for sparse enums.
>>
> Thanks.
> I don't think I use sparse enums. Mine are declared like:
> type aEnum = (Val1, Val2);
>
> So I think the Succ/Pred should work.

They do, and so do low/high:

$ cat tt2.pp
type aEnum = (Val1, Val2);

var
   e: aEnum;
begin
   for e := low(aEnum) to high(aEnum) do
     writeln(ord(e));
end.
$ /usr/local/lib/fpc/2.2.4/ppcppc tt2
Free Pascal Compiler version 2.2.4 [2009/04/05] for powerpc
Copyright (c) 1993-2008 by Florian Klaempfl
Target OS: Darwin for PowerPC
Compiling tt2.pp
Assembling program
Linking tt2
8 lines compiled, 0.4 sec
$ ./tt
ea

I thought you were talking about sparse enums because you said that  
low/high didn't work.


Jonas



More information about the fpc-pascal mailing list