[fpc-devel] TShiftState as enum

Vinzent Hoefler JeLlyFish.software at gmx.net
Thu Feb 17 12:43:40 CET 2005


On Thursday 17 February 2005 07:37, Marco van de Voort wrote:

> type myset = set of ( a1,a2,a3,a4,a5,a6);
>
> // workaround types
> const
>      beginmyset=ord(low(myset));
>      endmyset=ord(high(myset));
> type
>      uglyenum = beginmyset..endmyset;
>      uglyset= set of uglyenum;
>
> var b : myset;
>     i : integer;
>
> begin
>   b:=[a1,a2,a3];
>   for i:=ord(low(myset)) to ord(high(myset)) do
>     if i in uglyset(b) then writeln(i);
> end.

"Almost every complex solution ...":

type
   My_Set = set of (a1, a2, a3, a4, a5, a6);

// workaround type
type
   Ugly_Enum = Low (My_Set) .. High (My_Set);

var
   b : My_Set;
   i : Ugly_Enum;

begin
   b := [a1, a2, a3, a5];

   for i := Low (b) to High (b) do
      if i in b then
         WriteLn (Ord (i));
end.

Personally I would prefer to first define the enum and the "set of enum" 
then. While looking at it: Notice that the code above just reverses the 
order of the definitions which you need anyway. Quite awkward, I think.


Vinzent.





More information about the fpc-devel mailing list