我现在有10个CheckBox,即CheckBox1..CheckBox10
现在想做一个循环
var
i:integer;
for i:=1 to 10 do
begin
if CheckBoxi.Checked then
begin
......
end;
end;
上面我写的不对,但是是要实现这样的功能,不知道该怎么改,谢谢!
...全文
928打赏收藏
一个简单问题
我现在有10个CheckBox,即CheckBox1..CheckBox10 现在想做一个循环 var i:integer; for i:=1 to 10 do begin if CheckBoxi.Checked then begin ...... end; end; 上面我写的不对,但是是要实现这样的功能,不知道该怎么改,谢谢!
这个函数需要是窗体中的函数,否则要改成这样:
var
i:integer;
for i:=1 to 10 do
begin
if TCheckBox(Form1.FindComponent('CheckBox'+IntTostr(i))).Checked then {Form1是窗体名}
begin
......
end;
end;
我现在有10个CheckBox,即CheckBox1..CheckBox10
现在想做一个循环
var
i:integer;
for i:=1 to 10 do
begin
if TCheckBox(FindComponent('CheckBox'+IntTostr(i))).Checked then {if CheckBoxi.Checked then}
begin
......
end;
end;
var CheckBox:array[1..10] of TCheckBox;
i:integer;
for i:=1 to 10 do
begin
CheckBox[i]:=TCheckBox.Create(self);
CheckBox[i].Parent:=Form1;
CheckBox[i].Top:=i*20;
CheckBox[i].Caption:='CheckBox'+IntToStr(i);
CheckBox[i].Show;
end;
for i:=1 to 10 do
begin
if CheckBox[i].Checked then
begin
......
end;
end;
var
i:integer;
l_Checkbox: TComponent;
for i:=1 to 10 do
begin
l_Checkbox:=FindComponent('CheckBox' + IntToStr(i));
if (l_CheckBox is TCheckBox) and (l_CheckBox as TCheckBox).checked then
begin
......
end;
end;