I know I can do that:
const
arrayOfIntegers : Array[1..15] of Integer = (3,2,8,10,1,6,2,13,13,3,13,13,13,3,45);
But how can I do the following instead?
var
arrayOfIntegers : Array[1..15] of Integer;
begin
arrayOfIntegers := (3,2,8,10,1,6,2,13,13,3,13,13,13,3,45);
end;
As soon as I try to compile the code above I get E2029 ‘)’ expected but ‘,’ found
A typical use will be the following:
You should better define your own type in this case (code won’t be slower or bigger, and you’ll be able to make assignments between instances of this type). And you’ll ensure that your array boundaries will be as expected (1..15).
The
conststatement will be compiled as a “reference” array, which will be copied in yourarrayOfIntegerslocal variable. I’ve made it uppercase, which a somewhat commmon usage when declaring constants (but not mandatory – this is just a personal taste).If you want your code to be more generic and reusable (which IMHO makes sense if you want to be a lazy programmer) you may rely on dynamic arrays, and/or
array of constparameters (if your array start with index 0).