delphi中想把选择的CheckBox的值获取过来,怎么老提示错误?
我的窗体中有11个CheckBox。代码这么写的:
var
i:integer;
varstr:string;
begin
//获取选项值
for i:=1 to 11 do
begin
if(CheckBox[i].Checked=true) then
begin
varstr:=varstr+ CheckBox[i].caption;
end;
showmessage(varstr);
end;
if(CheckBox[i].Checked=true) then句中老是提示
“Undeclared identifier: 'CheckBox'”
[解决办法]
for i:=0 to mainfrm.ComponentCount-1 do begin if ((mainfrm.Components[i] is TCheckbox).Checked=true) then begin varstr:=varstr+(mainfrm.Components[i] is TCheckbox).caption; end; end;