Hi, I have a few const arrays of the same base type but different sizes, and I need to point to them in the const records. The code below compiles successfully, but finishes with error.
type
Toffsets = array of integer;
Trec = record
point1: Tpoint; //complete size
point2: Tpoint;
aOffsets: ^Toffsets;
end;
const
cOffsetsA: array [0..3] of integer = (7, 4, 2, 9);
cOffsetsB: array [0..5] of integer = (1, 2, 3, 4, 5, 6);
cRec1: Trec = (
point1: (x: 140; y: 46);
point2: (x: 5; y: 7);
aOffsets: @cOffsetsA;
);
cRec2: Trec = (
point1: (x: 40; y: 6);
point2: (x: 5; y: 7);
aOffsets: @cOffsetsB;
);
In my code I need to access data from the cOffsetsA/B arrays having a pointer to the record. I tried to do it like this:
var pMyRec: ^Trec;
...
pMyRec := @cRec1;
...
i := pMyRec^.aOffsets^[0];
and this causes error - 'Access violation ... read of address 000000...'
Can anybody explain is wrong here and how to fix it, how should it be done?
Probably I will also have to add the _length field in the record, which will hold the size of the array the pointer is pointing to; this is not a problem.
Best regards, LUK