I’m perfectly avare that pointer math in Delphi should be used with special care, but I still don’t get where am I wrong here. Let’s take a look on the following type definition:
program Project26;
{$POINTERMATH ON}
type
TCalibrationTable = array [0 .. 3] of byte;
PCalibrationTable = ^TCalibrationTable;
Now I need 2 arrays, each of them having 3 elements of TCalibrationTable
(ultimately they are 2-dimensional, 3 × 4 arrays).
And also need a header which points to a pair of such array objects.
var
table0: array [0 .. 2] of TCalibrationTable;
table1: array [0 .. 2] of TCalibrationTable;
header: array [0 .. 1] of PCalibrationTable;
Let’s initialize the header: the most comfortable way to access an array by a pointer is to assign it the first element’s address, then simply index the pointer to get an arbitrary element.
begin
header[0] := @table0[0];
header[1] := @table1[0];
Now, header[0]
being a PCalibrationTable
, I can use it to index it in order to get arbitrary TCalibrationTable
typed elements from an array. In this way header[0][2]
SHOULD BE a TCalibrationTable
, that is, an array of 4 elements of byte
.
But the following assignment will give a build error: Array type required.
header[0][2][3] := 100;
end.
Why?