What RRUZ says is completely correct.
To add a little more explanation, in 64-bit Delphi, dynamic array indexes can be 64 bits wide. This is clearly necessary, for example, when working with a large TBytes memory block. And therefore, the high function should return a value of a type wide enough to hold all possible indexes. So, high when applied to a dynamic array returns an Int64 value.
As soon as you start compiling 64-bit code, the in statement is not suitable for the problem you are trying to solve. Although you can use the cast that RRUZ offers, it might be clearer to write code like this
if (I=low(L)) or (I=high(L)) then
While the in operator does for completely readable code, I find casting to Integer here unacceptable. This will just set a trap for you when you first get an array with more than high(Integer) elements. When this happens, the throw code will stop working.
But in fact, the problems go much deeper than that. The in version of the code does not fire long before you reach the high(Integer) elements. Turns out your code, while it compiles, actually doesn't work. For example, consider this program:
program WeirdSets; {$APPTYPE CONSOLE} uses SysUtils; var a: array of Integer; begin SetLength(a, 257); Writeln(BoolToStr(Length(a) in [0, Length(a)], True)); end.
You expect this program to output True , but in fact it outputs False . If instead you should have written
Writeln(BoolToStr(Length(a) in [0, 257], True));
then the compiler reports:
[DCC Error] WeirdSets.dpr(9): E1012 Constant expression violates subrange bounds
The main problem here is that the sets are limited to 256 elements, so as soon as you have an array with a longer length, your code will stop working.
Unfortunately, the Delphi support for the sets is simply inadequate and requires urgent attention.
I also wonder if you really intended to write
if I in [0..High(L)] then
If so, I would recommend using the InRange function from Math .
if InRange(I, 0, High(L)) then
or even better
if InRange(I, low(L), High(L)) then