相关代码如下:procedure TForm2.ComboBox1Change(Sender: TObject);
var
i,j,count:integer;
tt:array of Tedit;
begin
j:= Panel1.ControlCount;
while Panel1.ControlCount >0 do begin
Panel1.Controls[j-1].Free;
j:=j-1;
end;
count:=strtoint(combobox1.items[combobox1.ItemIndex]);
for i:=0 to count-1 do
begin
tt[i]:=Tedit.Create(self);
tt[i].Visible:=true;
tt[i].left:=10;
tt[i].parent:=Panel1;
tt[i].top:=30*i+10;
end;
end;编译通过了,但是运行时提醒错误:“tt”might not have been intialized.
var
i,j,count:integer;
tt:array of Tedit;
begin
j:= Panel1.ControlCount;
while Panel1.ControlCount >0 do begin
Panel1.Controls[j-1].Free;
j:=j-1;
end;
count:=strtoint(combobox1.items[combobox1.ItemIndex]);
for i:=0 to count-1 do
begin
tt[i]:=Tedit.Create(self);
tt[i].Visible:=true;
tt[i].left:=10;
tt[i].parent:=Panel1;
tt[i].top:=30*i+10;
end;
end;编译通过了,但是运行时提醒错误:“tt”might not have been intialized.
解决方案 »
- 小弟刚开始学delphi,问个弱弱的问题,delphi2009如何新建windows forms application?....
- 64位windows 2008,64位oracle g11及64位客户端 oracleOLEDB报错
- 初学Delphi,麻烦推荐一个显示动态Gif的控件
- 急,有关第三方控件的问题!
- 怎样从try的 except 处得到产生异常的代码的行号?
- 请教ADO组件中Adotable,Adoconnection.Adoquery,,,,的各个用法,在什么时侯用才能更多好!?在线等待~
- 怎么实现??最好有源代码!!!
- 如何在delphi中用XSD验证XML的格式啊?
- 如何发消息给服务程序?
- 一个关于sql模糊查询的问题
- 帮我看一个问题
- 进销存中的模糊查找
...
setlength(tt,count-1);
for i:= ...
procedure TForm2.ComboBox1Change(Sender: TObject);
var
i,j,count:integer;
tt:array of Tedit;
begin
j:= Panel1.ControlCount;
while Panel1.ControlCount >0 do
begin
Panel1.Controls[j-1].Free;
j:=j-1;
end;
count:=strtoint(combobox1.items[combobox1.ItemIndex]);
setlength(tt,count-1); //动态数组使用前要设置大小
for i:=0 to count-1 do
begin
tt[i]:=Tedit.Create(self);
tt[i].Visible:=true;
tt[i].left:=10;
tt[i].parent:=Panel1;
tt[i].top:=30*i+10;
end;
end;
setlength(tt, count); //动态数组使用前要设置大小
语句中count是指定的新大小值,而在索引时由于动态数组是0起始的,所以最大索引值是count- 1
就是没有SetLength