Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude the first element of an enumerated Type used as an array index in delphi?

Tags:

delphi

I want to exclude the first value of this enumerated type

type
  TEnum = (val0, val1, val2, val3, val4);

in order to make this array

TBValues: array [low(TEnum)..High(TEnum)] of boolean;

contains only the last n-1 values (in this case n=5).

I tried this:

TBValues: array [low(TEnum)+1..High(TEnum)] of boolean; 

but I guess arithmetic operations are not allowed in this case because I'm getting this compiler error

E2010 Incompatible types: 'Int64' and 'TEnum'

How to do this?

like image 724
Nasreddine Galfout Avatar asked Nov 14 '17 16:11

Nasreddine Galfout


1 Answers

What about the obvious:

TBValues: array [val1..val4] of boolean;

If you want to avoid the actual enum names, you can write it this way:

TBValues: array [Succ(low(TEnum))..High(TEnum)] of boolean;

For more information:

  • Succ
  • Pred
like image 153
Uwe Raabe Avatar answered Nov 16 '22 20:11

Uwe Raabe