读书人

delphi动态数组有关问题

发布时间: 2012-02-23 22:01:35 作者: rapoo

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;
为什么运行之后出错?

[解决办法]
字符串的下标引用不能从0开始,应该写为str[i+1]:=ComboBox1.Items[I];
[解决办法]
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;

读书人网 >.NET

热点推荐