Problem with RadioGroup.ControlCount in Delphi 2010

独自空忆成欢 提交于 2019-12-31 03:44:47

问题


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;

回答1:


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.



来源:https://stackoverflow.com/questions/2126620/problem-with-radiogroup-controlcount-in-delphi-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!