Delphi 2010 中 RadioGroup.ControlCount 的问题

发布于 2024-08-19 08:06:39 字数 546 浏览 4 评论 0原文

我想在运行时在过程 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情出卖 2024-08-26 08:06:39

我假设调用您的过程时 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文