我写的程序为:
var
I:integer;
begin
I:=ComboBox1.Items.Count-1;
SetLength(str,I);
I:=0;
for I:=0 to ComboBox1.Items.Count-1 do
begin
str[i]:=ComboBox1.Items[I];
end;
为什么运行之后出错?
...全文
6935打赏收藏
delphi动态数组问题?
我写的程序为: var I:integer; begin I:=ComboBox1.Items.Count-1; SetLength(str,I); I:=0; for I:=0 to ComboBox1.Items.Count-1 do begin str[i]:=ComboBox1.Items[I]; end; 为什么运行之后出错?
var
I:integer;
str:array of string;//.....?
begin
I:=ComboBox1.Items.Count;
SetLength(str,I);//如果不是上面的定义,你只分配了一个字符串,并不是字符串数组。
I:=0;
for I:=0 to ComboBox1.Items.Count-1 do
begin
str[i]:=ComboBox1.Items[I];
end;
var
I:integer;
begin
I:=ComboBox1.Items.Count; //不要-1
SetLength(str,I);
I:=0;
for I:=0 to ComboBox1.Items.Count-1 do
begin
str[i+1]:=ComboBox1.Items[I]; //str[i+1]
end;