Why the following code:
const
ANSICOLORS: array of cardinal = [
$000000,//0
$800000,//1, compilation error starts with this value
$008000,//2
$808000,//3
$000080,//4
$800080,//5
$008080,//6
$D0D0D0,//7
$3F3F3F,//8
$FF0000,//9
$00FF00,//A
$FFFF00,//B
$0000FF,//C
$FF00FF,//D
$00FFFF,//E
$FFFFFF];//F
Would produce the following compilation error under Delphi XE4 (both win32 and win64):
[dcc32 Error] Debug.pas(66): E1012 Constant expression violates subrange bounds
Isn't value $800000 within the range of Cardinal?
From a memory perspective,
$800000indeed is within the range ofCardinal.I thought it the
Cardinal($800000)typecast would fix it, but it doesn't.Delphi XE7 and up actually compile your code correctly.
This also fails up until Delphi XE6 with the same error:
I think the reason is that the Delphi compiler sees
[257]as aset, despite the left side indicating it is supposed to be anarray.This fails in XE4, but compile fine in XE7 and up:
Output:
If you can live with a non-dynamic array, then the below example works in Delphi XE4 (I tested it as far back as Delphi 2007, for XE and earlier, you have to replace
System.SysUtilswithSysUtils)).Note the switches:
array of Cardinaltoarray[0..15] of Cardinal[and]to(and)