Inno设置:设置ActiveControl属性

时间:2018-12-24 10:06:46

标签: inno-setup pascalscript

我试图将按钮聚焦在自定义选项窗口中,该窗口以模态显示。我已经读过Prevent button from receiving focus in Inno Setup,并尝试使用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;

但是,运行此命令时,会出现以下错误:

Runtime Error

我尝试通过在显示窗口之后放置它来更改调用时间,但是直到窗口关闭时它才被调用,因为ShowModal仍然给出相同的错误时会停止脚本执行。有没有一种方法可以将按钮设置为在模式窗口中集中显示?

1 个答案:

答案 0 :(得分:1)

您的代码是imo正确的。对我来说似乎是个虫子。

触发问题的是OptionsWindowForm.Parent属性的设置。只需将其删除。

enter image description here