procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to self.ComponentCount - 1 do
begin
if self.Components is Tedit then
begin
(Self.Components as Tedit).enabled := false;//perhaps true
end;
end;
end;
procedure TForm1.EnabledLabel(Onoff: Boolean;SelectGroup:Integer);
var
i: integer;
begin
for i:=0 to ComponentCount-1 do
if Components is TLabel
then if TLabel(Components).tag=SelectGroup
then TLabel(Components).enabled:=OnOff;
end;
嗯,是的,确实一定要动态生成。
不过这并不麻烦,对于一个LABEL来说,常需设置的有left,top,caption三个属性,而前两个基本上也是有一定规律的,程序修改如下:
type Tmylabel=class(Tlabel);
var mylabel:array [1..50] of Tmylabel;
i:integer;
begin
for i:=1 to 50 do
begin
mylabel.create(form1);
mylabel.parent:=form1;
mylabel.enabled:=false;
mylabel.left=...;
mylabel.top=...;
case i of
1:mylabel.caption:='...';
2:mylabel.caption:='...';
......
end;
end;
end;
如果你的LABEL的编号是连续的:
var
i:integer;
str:string;
lab:tlabel;
begin
for i:=1 to 50 do
begin
str:='label'+inttostr(i);
lab:=form1.findcomponent(str);
(lab as tlabel).enabled:=false;
end;
end;