我想在过程 InitRadioGroup() 的运行时设置 RadioButton 属性.它失败是因为 RadioGroup.ControlCount 为 0,尽管 RadioGroup 中有 3 个 RadioButton.
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.
D2010 RadioGroup 出了什么问题?相同的代码在 Delphi 2007 中运行良好.
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;
我假设 RadioGroup 在调用您的过程时不可见.所以那时可能不会创建 RadioButtons.
I assume that the RadioGroup is not visible when your procedure is called. So the RadioButtons may not be created then.
调用 RadioGroup.HandleNeeded
应该会为您解决此问题.
A call to RadioGroup.HandleNeeded
should fix this for you.