首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi动态数组有关问题

2012-02-23 
delphi动态数组问题?我写的程序为:varI:integerbeginI:ComboBox1.Items.Count-1SetLength(str,I)I:0

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;

热点排行