Access violation in Delphi?

die*_*lar 0 arrays delphi exception matrix

我得到了以下代码,它应该正确地访问矩阵位置,但是我总是得到这种访问违规...

var
tabla : array of array of string;

....
implementation

SetLength(tabla, minterms.Count+1, minterms_essentials.Count+1);

for i := 0 to minterms.Count-1 do
begin
  tabla[i+2,1] := minterms[i];
end;

for i := 0 to minterms_essentials.Count-1 do
begin
  tabla[1, i+2] := minterms_essentials[i];
end;

end
Run Code Online (Sandbox Code Playgroud)

基本上,我正在生成一个表,在循环中我试图在第二个循环中填充列标记和行标记.只要我知道,数组从1开始.

tabla[1][1]是一个空置的指数,这就是为什么我没有触及它.

为什么访问违规?

Mas*_*ler 6

在Delphi中,动态数组(你可以调用SetLength的任何数组,而不是在编译时声明它的边界array[1..5] of integer)从0开始索引,而不是从1开始.因此,将数组视为使用基于1的索引而不是基于0的索引,你溢出数组的边界,并试图写入未分配给你的内存,这可能会导致访问冲突.