procedure TForm1.Button2Click(Sender: TObject); var i : Integer; begin for i := 0 to self.ComponentCount-1 do if self.Components[i] is TLabel then (self.Components[i] as TLabel).Caption := 'abc'; end;
给你一个例子,是在FORM1放入N个Radiobutton,然后点击哪个就哪个字体变色: procedure tform1.aa; var i:integer; s:string; begin for i := 0 to self.componentcount-1 do if self.components[i] is TradioButton then if (self.components[i] as TradioButton).checked then begin (self.components[i] as TradioButton).Color :=clskyblue; end else (self.components[i] as TradioButton).Color :=clBtnFace; end; 请别忘记声明,使用时,在每个TradioButton的click事件中调用这个过程就行了
var I: Integer; begin for I := 0 to ControlCount -1 do if Controls[i].ClassNmae = Tlabel then with Tlabel(Controls[i]) do if caption='abc' then showmessage(caption);
var i:integer; str:string; begin for i:=0 to componentcount-1 do if (components[i] is TLabel)and((components[i] as TLabel).Caption='abc') then begin str:=(components[i] as TLabel).Name; showmessage(str); end;
procedure TForm1.Button1Click(Sender: TObject); var i : Integer; begin for i := 0 to self.ComponentCount-1 do if self.Components[i] is TLabel then if (self.Components[i] as TLabel).Caption <> 'abc' then begin (self.Components[i] as TLabel).Visible:=false; end; end;
var
i : Integer;
begin
for i := 0 to self.ComponentCount-1 do
if self.Components[i] is TLabel then
(self.Components[i] as TLabel).Caption := 'abc';
end;
procedure tform1.aa;
var
i:integer;
s:string;
begin
for i := 0 to self.componentcount-1 do
if self.components[i] is TradioButton then
if (self.components[i] as TradioButton).checked then
begin
(self.components[i] as TradioButton).Color :=clskyblue;
end
else
(self.components[i] as TradioButton).Color :=clBtnFace;
end;
请别忘记声明,使用时,在每个TradioButton的click事件中调用这个过程就行了
I: Integer;
begin
for I := 0 to ControlCount -1 do
if Controls[i].ClassNmae = Tlabel then
with Tlabel(Controls[i]) do
if caption='abc' then
showmessage(caption);
str:string;
begin
for i:=0 to componentcount-1 do
if (components[i] is TLabel)and((components[i] as TLabel).Caption='abc') then
begin
str:=(components[i] as TLabel).Name;
showmessage(str);
end;
var
i : Integer;
begin
for i := 0 to self.ComponentCount-1 do
if self.Components[i] is TLabel then
if (self.Components[i] as TLabel).Caption <> 'abc' then
begin
(self.Components[i] as TLabel).Visible:=false;
end;
end;