[fpc-pascal] For .. in .. loops with sets and valued enums

Peter peter at pblackman.plus.com
Fri Jun 19 10:50:58 CEST 2015


On 19/06/15 08:46, Torsten Bonde Christiansen wrote:
> program Project1;
>
> type
>   TMyEnum = (
>     a = 1,
>     b = 3,
>     c = 5
>   );
>   TMySet = set of TMyEnum;
> var
>   Item: TMyEnum;
>
> begin
>   for Item in TMySet do
>     Writeln('Value = ', Integer(Item));
> end.

My guess is that you are iterating a set type, that is wide enough to
hold all 5 values.
Iterating a set var produces the expected output.

program Project1;

type
  TMyEnum = (
    a = 1,
    b = 3,
    c = 5
  );
  TMySet = set of TMyEnum;
var
  Item: TMyEnum;
  MySet : TMySet = [a,b,c];

begin
  for Item in MySet do
    Writeln('Value = ', Integer(Item));
end.


Still, I can see your point.



More information about the fpc-pascal mailing list