L
lzh1998
Unregistered / Unconfirmed
GUEST, unregistred user!
如下执行第二次(当i=1)程序出错project proshuru.exe raised exception class Einvalidcast with message'Invalid class typecast'.
process stopped.Use step or run to continue )
var i,j:integer;
ttxt:TLabel;
text:tedit;
begin
i:=0;
j:=0;
while Form1.dbgrideh1.columns.Count>j do
begin
ttxt:=tlabel.Create(self);
ttxt.Parent:=ScrollBox1;
(form2.ScrollBox1.Controls as tlabel).Name:='ttxt'+inttostr(j);
(form2.ScrollBox1.Controls as tlabel).Caption:=Form1.dbgrideh1.columnS[j].Title.Caption+':';
(form2.ScrollBox1.Controls as tlabel).Left:=40;
(form2.ScrollBox1.Controls as tlabel).Top:=i*20;
i:=i+1;
text:=tedit.Create(self);
text.Parent:=ScrollBox1;
(form2.ScrollBox1.Controls as tedit).Name:='text'+inttostr(j);
(form2.ScrollBox1.Controls as tedit).Left:=100+40;
(form2.ScrollBox1.Controls as tedit).Top:=j*20;
i:=i+1;
j:=j+1;
end;
如果把如下删除掉就不会错了 为什么,上面的代码怎么救
text:=tedit.Create(self);
text.Parent:=ScrollBox1;
(form2.ScrollBox1.Controls as tedit).Name:='text'+inttostr(j);
(form2.ScrollBox1.Controls as tedit).Left:=100+40;
(form2.ScrollBox1.Controls as tedit).Top:=j*20;
i:=i+1;
process stopped.Use step or run to continue )
var i,j:integer;
ttxt:TLabel;
text:tedit;
begin
i:=0;
j:=0;
while Form1.dbgrideh1.columns.Count>j do
begin
ttxt:=tlabel.Create(self);
ttxt.Parent:=ScrollBox1;
(form2.ScrollBox1.Controls as tlabel).Name:='ttxt'+inttostr(j);
(form2.ScrollBox1.Controls as tlabel).Caption:=Form1.dbgrideh1.columnS[j].Title.Caption+':';
(form2.ScrollBox1.Controls as tlabel).Left:=40;
(form2.ScrollBox1.Controls as tlabel).Top:=i*20;
i:=i+1;
text:=tedit.Create(self);
text.Parent:=ScrollBox1;
(form2.ScrollBox1.Controls as tedit).Name:='text'+inttostr(j);
(form2.ScrollBox1.Controls as tedit).Left:=100+40;
(form2.ScrollBox1.Controls as tedit).Top:=j*20;
i:=i+1;
j:=j+1;
end;
如果把如下删除掉就不会错了 为什么,上面的代码怎么救
text:=tedit.Create(self);
text.Parent:=ScrollBox1;
(form2.ScrollBox1.Controls as tedit).Name:='text'+inttostr(j);
(form2.ScrollBox1.Controls as tedit).Left:=100+40;
(form2.ScrollBox1.Controls as tedit).Top:=j*20;
i:=i+1;