procedure TForm1.CheckBox1Click(Sender: TObject); begin if sender is TCheckBox then TCheckBox(sender).Caption := TCheckBox(sender).Caption + inttostr(TCheckBox(sender).tag) else if Sender is TRadioButton then TRadioButton(Sender).Caption := TRadioButton(Sender).Caption + inttostr(TRadioButton(Sender).tag); end;procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin for i := 0 to ComponentCount - 1 do begin if Components[i] is TCheckBox then begin TCheckBox(Components[i]).ONClick := CheckBox1Click; CheckBox1Click(Components[i]); end else if Components[i] is TRadioButton then begin TRadioButton(Components[i]).OnClick := CheckBox1Click; CheckBox1Click(Components[i]); end; end; end;
procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin for i := 0 to Form1.ComponentCount - 1 do begin if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then if TButtonControl(Components[i]).Tag in [1..3] then TButtonControl(Components[i]).Visible := False else if TButtonControl(Components[i]).Tag in [4..6] then TButtonControl(Components[i]).Visible := True; end; end;
是这样吗? procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin for i := 0 to Form1.ComponentCount - 1 do begin if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then if TButtonControl(Components[i]).Tag in [1..3] then TButtonControl(Components[i]).Visible := False else if TButtonControl(Components[i]).Tag in [4..6] then TButtonControl(Components[i]).Visible := True; end; end;
不好意思上面的写反了! procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin for i := 0 to Form1.ComponentCount - 1 do begin if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then if TButtonControl(Components[i]).Tag in [1..3] then TButtonControl(Components[i]).Visible := True else if TButtonControl(Components[i]).Tag in [4..6] then TButtonControl(Components[i]).Visible := False; end; end;
procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin //对GroupBox1上的控件操作 for i := 0 to Form1.ComponentCount - 1 do begin if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then if TButtonControl(Components[i]).Parent.Name = 'GroupBox1' then if TButtonControl(Components[i]).Tag in [1..3] then TButtonControl(Components[i]).Visible := True else if TButtonControl(Components[i]).Tag in [4..6] then TButtonControl(Components[i]).Visible := False; end; end;
for i:=GroupBox.ControlCount-1 downto 0 do (GroupBox.Controls[i] as TRadioButton).Visible :=False
Kingron(单身走我路……)写得更简洁!
procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin for i := 0 to GroupBox1.ControlCount - 1 do begin if (GroupBox1.Controls[i] is TCheckBox) or (GroupBox1.Controls[i] is TRadioButton) then if GroupBox1.Controls[i].Tag in [1..3] then TButtonControl(GroupBox1.Controls[i]).Visible := True else if GroupBox1.Controls[i].Tag in [4..6] then TButtonControl(GroupBox1.Controls[i]).Visible := False; end;end;
begin
if sender is TCheckBox then
TCheckBox(sender).Caption := TCheckBox(sender).Caption + inttostr(TCheckBox(sender).tag)
else if Sender is TRadioButton then
TRadioButton(Sender).Caption := TRadioButton(Sender).Caption + inttostr(TRadioButton(Sender).tag);
end;procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
for i := 0 to ComponentCount - 1 do
begin
if Components[i] is TCheckBox then
begin
TCheckBox(Components[i]).ONClick := CheckBox1Click;
CheckBox1Click(Components[i]);
end
else if Components[i] is TRadioButton then
begin
TRadioButton(Components[i]).OnClick := CheckBox1Click;
CheckBox1Click(Components[i]);
end;
end;
end;
var
i: integer;
begin
for i := 0 to Form1.ComponentCount - 1 do
begin
if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then
if TButtonControl(Components[i]).Tag in [1..3] then
TButtonControl(Components[i]).Visible := False
else if TButtonControl(Components[i]).Tag in [4..6] then
TButtonControl(Components[i]).Visible := True;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
for i := 0 to Form1.ComponentCount - 1 do
begin
if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then
if TButtonControl(Components[i]).Tag in [1..3] then
TButtonControl(Components[i]).Visible := False
else if TButtonControl(Components[i]).Tag in [4..6] then
TButtonControl(Components[i]).Visible := True;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
for i := 0 to Form1.ComponentCount - 1 do
begin
if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then
if TButtonControl(Components[i]).Tag in [1..3] then
TButtonControl(Components[i]).Visible := True
else if TButtonControl(Components[i]).Tag in [4..6] then
TButtonControl(Components[i]).Visible := False;
end;
end;
万分感谢!!!
var
i: integer;
begin
//对GroupBox1上的控件操作
for i := 0 to Form1.ComponentCount - 1 do
begin if (Components[i] is TCheckBox) or (Components[i] is TRadioButton) then
if TButtonControl(Components[i]).Parent.Name = 'GroupBox1' then
if TButtonControl(Components[i]).Tag in [1..3] then
TButtonControl(Components[i]).Visible := True
else if TButtonControl(Components[i]).Tag in [4..6] then
TButtonControl(Components[i]).Visible := False;
end;
end;
(GroupBox.Controls[i] as TRadioButton).Visible :=False
var
i: integer;
begin
for i := 0 to GroupBox1.ControlCount - 1 do
begin
if (GroupBox1.Controls[i] is TCheckBox) or (GroupBox1.Controls[i] is TRadioButton) then
if GroupBox1.Controls[i].Tag in [1..3] then
TButtonControl(GroupBox1.Controls[i]).Visible := True
else if GroupBox1.Controls[i].Tag in [4..6] then
TButtonControl(GroupBox1.Controls[i]).Visible := False;
end;end;