Delphi 2010 中 RadioGroup.ControlCount 的问题
我想在运行时在过程 InitRadioGroup() 中设置 RadioButton 属性。 它失败,因为 RadioGroup.ControlCount 为 0,尽管 RadioGroup 中有 3 个 RadioButton。
D2010 RadioGroup 有什么问题? 相同的代码在 Delphi 2007 中运行良好。
procedure InitRadioGroup(RadioGroup: TRadioGroup);
var
i: integer;
RadioButton: TRadioButton;
begin
for i := 0 to RadioGroup.ControlCount - 1 do
begin
RadioButton := (RadioGroup.Controls[i] as TRadioButton);
RadioButton.ParentColor := False;
RadioButton.ParentFont := False;
RadioButton.Font.Style := [];
end;
I'd like to set RadioButton properties in runtime in procedure InitRadioGroup().
It fails because RadioGroup.ControlCount is 0, although there are 3 RadioButtons in RadioGroup.
What is wrong in D2010 RadioGroup?
Same code works fine in Delphi 2007.
procedure InitRadioGroup(RadioGroup: TRadioGroup);
var
i: integer;
RadioButton: TRadioButton;
begin
for i := 0 to RadioGroup.ControlCount - 1 do
begin
RadioButton := (RadioGroup.Controls[i] as TRadioButton);
RadioButton.ParentColor := False;
RadioButton.ParentFont := False;
RadioButton.Font.Style := [];
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设调用您的过程时 RadioGroup 不可见。因此,RadioButtons 可能不会被创建。
调用
RadioGroup.HandleNeeded
应该可以解决这个问题。I assume that the RadioGroup is not visible when your procedure is called. So the RadioButtons may not be created then.
A call to
RadioGroup.HandleNeeded
should fix this for you.