你把这些单选框定义成数组:ch:array[30] of TcheckBox;运行的时候动态生成就行了循环检查ch[i].check,再改为0或1就行了.
随便讲讲,可能不对 ch:array[30] of TcheckBox; 这样只是定义,不实例化的话,可以用ch[i].check? 是不是应该定义指针的数组?
for Index:=0 to ControlCount-1 do begin if Components[Index] is TCheckBox then ZeroOne[Index]:=(Components[Index] as TCheckBox).Check; end;试试看
不对有写错,不好意思 var count:integer=0; for Index:=0 to ControlCount-1 do begin if Components[Index] is TCheckBox then begin inc(Count) ZeroOne[Count]:=(Components[Index] as TCheckBox).Check; end; end;
这样就可以容易管理它们了!
单选的话直接用radiogroup相当简单
ch:array[30] of TcheckBox;
这样只是定义,不实例化的话,可以用ch[i].check?
是不是应该定义指针的数组?
begin
if Components[Index] is TCheckBox then
ZeroOne[Index]:=(Components[Index] as TCheckBox).Check;
end;试试看
var count:integer=0;
for Index:=0 to ControlCount-1 do
begin
if Components[Index] is TCheckBox then
begin
inc(Count)
ZeroOne[Count]:=(Components[Index] as TCheckBox).Check;
end;
end;