Inno Setup:"Cannot focus disabled or invisible window" 同时设置 ActiveControl 属性

Inno Setup: "Cannot focus disabled or invisible window" while setting ActiveControl property

我正在尝试将按钮置于自定义选项 window 中,该选项以模态方式显示。我已经阅读了 并尝试使用 ActiveControl 属性 来设置它。这是代码:

[Code]

{ Create and show the Options window }
procedure ShowOptionsWindow;
var
  OptionsOKButton, OptionsCancelButton: TButton;
begin
  OptionsWindowForm := TForm.Create(WizardForm);
  with OptionsWindowForm do
    begin
      Parent := WizardForm;
      BorderStyle := bsDialog;
      Position := poOwnerFormCenter;
      ClientWidth := ScaleX(425);
      ClientHeight := ScaleY(165);
      Caption := '{#AppName} Options';
    end;
{ Define the Options Cancel button }
  OptionsCancelButton := TButton.Create(OptionsWindowForm);
  with OptionsCancelButton do
    begin
      Parent := OptionsWindowForm;
      Left := (OptionsWindowForm.ClientWidth - WizardForm.NextButton.Width) - (WizardForm.ClientWidth - (WizardForm.CancelButton.Left + WizardForm.CancelButton.Width));
      Top := (OptionsWindowForm.ClientHeight - WizardForm.NextButton.Height) - ScaleY(12);
      Width := WizardForm.NextButton.Width;
      Height := WizardForm.NextButton.Height;
      Caption := 'Cancel';
      OnClick := @OptionsCancelButtonClick;
    end;
{ Define the Options OK button }
  OptionsOKButton := TButton.Create(OptionsWindowForm);
  with OptionsOKButton do
    begin
      Parent := OptionsWindowForm;
      Left := (OptionsCancelButton.Left - WizardForm.NextButton.Width) - ((WizardForm.CancelButton.Left - WizardForm.NextButton.Left) - WizardForm.NextButton.Width);
      Top := OptionsCancelButton.Top;
      Width := WizardForm.NextButton.Width;
      Height := WizardForm.NextButton.Height;
      Caption := 'OK';
      OnClick := @OptionsOKButtonClick;
    end;
  OptionsWindowForm.ActiveControl := OptionsOKButton;
  OptionsWindowForm.ShowModal;
end;

但是,当运行这样的时候,会出现如下错误:

我尝试更改它的调用时间,将其放置在显示 window 之后,但直到 window 关闭后才调用它,因为 ShowModal 停止了脚本执行,当它仍然给出相同的错误时。有没有办法将按钮设置为在模态中聚焦 window?

我认为您的代码是正确的。这对我来说像是一个错误。

触发问题的是OptionsWindowForm.Parent 属性的设置。删除它即可。