将8个CheckBox 声明为一个数组,类型为TCheckBox,然后循环数组就可以了!ArrCheck:Array [0..7]of TCheckBox; for i:=0 to 7 do TCheckBox(ArrCheck[i]).Checked := False;
用CheckListBox或 将这些CheckBox放在一个GroupBox里, for i := 0 to GroupBox1.ControlCount - 1 do begin if GroupBox1.Controls[i] is TCheckBox then (GroupBox1.Controls[i] as TCheckBox).Checked := True; end;
for i := 0 to self.ComponentCount - 1 do begin if self.Components[i] is TCheckBox then (self.Components[i] as TCheckBox).Checked := True; end;
for i:=0 to ComponentCount-1 Do TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;
将8个CheckBox 声明为一个数组,类型为TCheckBox,然后循环数组就可以了!ArrCheck:Array [0..7]of TCheckBox; for i:=0 to 7 do TCheckBox(ArrCheck[i]).Checked := False;============================== 不行啊,有错,错误如下 --------------------------- Debugger Exception Notification --------------------------- Project RemoteII.exe raised exception class EAccessViolation with message 'Access violation at address 0053E1C7 in module 'RemoteII.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue. --------------------------- OK Help ---------------------------
for i:=0 to ComponentCount-1 Do TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;======================================== 谢谢了,搞定,结贴
for i:=0 to ComponentCount-1 Do ////for i:=0 这里改为:for i:=1才行 TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ with fmmain do begin .. end;
将这些CheckBox放在一个GroupBox里,
for i := 0 to GroupBox1.ControlCount - 1 do
begin
if GroupBox1.Controls[i] is TCheckBox then
(GroupBox1.Controls[i] as TCheckBox).Checked := True;
end;
begin
if self.Components[i] is TCheckBox then
(self.Components[i] as TCheckBox).Checked := True;
end;
TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;
不行啊,有错,错误如下
---------------------------
Debugger Exception Notification
---------------------------
Project RemoteII.exe raised exception class EAccessViolation with message 'Access violation at address 0053E1C7 in module 'RemoteII.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;========================================
谢谢了,搞定,结贴
如果我是控制其它窗体的checkbox 呢?
比如说是fmmain中的,又该怎么写呢?
fmmain.TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True; 吗?
这样好象不对。
TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
with fmmain do
begin
..
end;
这个前面加上form1,
比如:
Form4.TCheckBox(FindComponent('CheckBox' + IntToStr(i))).Checked :=True;
他就不认识了阿,
那如果不是在当前页面用这个checkbox又该怎么办呢??