可以这样写,循环所有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 //相关代码 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.