一组label的caption的赋值(90)

R

ranxg

Unregistered / Unconfirmed
GUEST, unregistred user!
我有四组label,从label11到label15,再到label45,共20个,现在要给每个label的caption赋值“11”...“15”...“45”,如何使用For i:=1 to 4 do for j:=1 to 5 do begin ???? end:来赋值?
 
你的方法可以阿。
 
????代码
 
For i:=0 To Form1.控件.Count-1 Doif Form1.控件 as TLable thenif Form1.控件.name='label1' Then ((Form1.控件) as TLabel).Caption:='nnnn';
 
可以这样写,循环所有TLabel控件,修改其Caption,(Label在Panel1中)procedure TForm1.Button1Click(Sender: TObject);var i: Integer;begin for i := 0 to Panel1.ControlCount-1 do begin if Panel1.Controls is TLabel then begin //根据Name设置Caption TLabel(Panel1.Controls).Caption := Copy(TLabel(Panel1.Controls).Name,6,2) end
end;end;
 
var x:integer
Comp: TComponent;begin for x:= 1 to 4 do begin Comp := FindComponent('label'+inttostr(x))
if Comp is TLabel then begin TLabel(Comp).Caption := inttostr(x)
end
end;//for x
 
难道不能用双重循环形式表示:For i:=1 to 4 do for j:=1 to 5 do begin //相关代码 end:来赋值?
 
就是这一句(//相关代码)不会!
 
难道不能用双重循环形式表示:来赋值? ----可以For i:=1 to 4 do for j:=1 to 5 do begin //相关代码 if form1.FindComponent('label'+inttostr(i *10 +j)) as tlable then tlabel(form1.FindComponent('label'+inttostr(i *10 +j))).caption:= inttostr(i *10 +j)
end:
 
楼上的可行!
 
For i:=1 to 4 do for j:=1 to 5 do begin //相关代码 if form1.FindComponent('label'+inttostr(i *10 +j)) as tlable then tlabel(form1.FindComponent('label'+inttostr(i *10 +j))).caption:= inttostr(i *10 +j)
end://更改为 if form1.FindComponent('label'+inttostr(i *10 +j)) is tlable ,是IS不是AS.
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
955
SUNSTONE的Delphi笔记
S
S
回复
0
查看
778
SUNSTONE的Delphi笔记
S
D
回复
0
查看
745
DelphiTeacher的专栏
D
D
回复
0
查看
747
DelphiTeacher的专栏
D
D
回复
0
查看
594
DelphiTeacher的专栏
D
顶部 底部