采用FMX写个APP要遍历一次窗体的复选框checkbox有多少处于选中状态,并显示出来。
用Vcl的代码是:
procedure TForm1.btn1Click(Sender: TObject);
var
i: Integer;
varstr: string;
begin
with Form1 do
for i := 0 to ComponentCount - 1 do
begin
if ((Components[i] is TCheckBox).Checked = True) then
begin
varstr := varstr+ (Components[i] is TCheckBox).Caption;
end;
end;
ShowMessage(varstr);
end;
但是在FMX下这些代码是通不过的,有些属性已经发生了变化。
最终把代码修改成如下:
procedure TForm1.btn1Click(Sender: TObject);
var
i: Integer;
varstr: string;
begin
with Form1 do
for i := 0 to ComponentCount - 1 do
begin
if (Components[i] is TCheckBox) and
((Components[i] as TCheckBox).IsChecked = True) then
begin
varstr := varstr + (Components[i] as TCheckBox).Text + #13;
end;
end;
ShowMessage(varstr);
end;
0 条评论
沙发空缺中,还不快抢~