//代码如下:实现将stringgrid1,stringgrid2中的数据分别存入数组G、B中。其中rowcount和colcount是根据用户设置可
//变化的。部分代码如下:好像是动态数组内存分配问题,请哪位高手指点
var
G,B:Array of array of double;procedure TForm2.SpeedButton2Click(Sender: TObject);
var
i,j:integer;
begin
with stringgrid1 do
begin
for i:=1 to stringgrid1.RowCount-1 do
for j:=i to stringgrid1.ColCount-1 do
begin
G[i,j]:=strtofloat(cells[j,i]);
end;
end;
with stringgrid2 do
begin
for i:=1 to stringgrid2.RowCount-1 do
for j:=i to stringgrid2.ColCount-1 do
begin
B[i,j]:=strtofloat(cells[j,i]);
end;
end;
end;
//变化的。部分代码如下:好像是动态数组内存分配问题,请哪位高手指点
var
G,B:Array of array of double;procedure TForm2.SpeedButton2Click(Sender: TObject);
var
i,j:integer;
begin
with stringgrid1 do
begin
for i:=1 to stringgrid1.RowCount-1 do
for j:=i to stringgrid1.ColCount-1 do
begin
G[i,j]:=strtofloat(cells[j,i]);
end;
end;
with stringgrid2 do
begin
for i:=1 to stringgrid2.RowCount-1 do
for j:=i to stringgrid2.ColCount-1 do
begin
B[i,j]:=strtofloat(cells[j,i]);
end;
end;
end;
var
num: arrray of string;
Begin
setlength(snum,10);
End;
动态数组的定义:Var A:Array of Array of string(定义为string类型的动态数组)
动态数组在定义时是不会分配内存空间的,
在是用时要是用SetLength进行内存分配,例如:SetLength(A,20)数组的个数是20个,数组下标是0到19你上面错误在,没有使用SetLength进行内存分配.
失踪的月亮给出的就是setlength(g,stringgrid1.RowCount,stringgrid1.ColCount);
作用就是给你申明的动态数组分配内存./