【发布时间】:2009-10-07 08:58:21
【问题描述】:
我有几个基本类型相同但大小不同的 const 数组,我需要在 const 记录中指向它们。下面的代码编译成功,但以错误结束。
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;
);
在我的代码中,我需要访问具有指向记录的指针的 cOffsetsA/B 数组中的数据。我试着这样做:
var pMyRec: ^Trec;
...
pMyRec := @cRec1;
...
i := pMyRec^.aOffsets^[0];
这会导致错误 - '访问冲突...读取地址 000000...'
谁能解释一下这里有什么问题以及如何解决它,应该怎么做?
可能我还必须在记录中添加 _length 字段,该字段将保存指针指向的数组的大小;这不是问题。
最好的问候, 卢克
【问题讨论】: