为什么在 Inno Setup 中没有选中自定义页面上的单选按钮?

Why doesn't the radio button on custom page checked in Inno Setup?

为什么 rbStandardInstallTyperbCustomInstallType 单选按钮没有被选中,即使我将其中一个的 Checked 属性 设置为 True?另一方面,rbDefaultMSSQLInstancerbNamedMSSQLInstance 单选按钮会被选中。

我这样创建单选按钮:

function CreateRadioButton(
  AParent: TNewNotebookPage; AChecked: Boolean; AWidth, ALeft, ATop, AFontSize: Integer;
  AFontStyle: TFontStyles; const ACaption: String): TNewRadioButton;
begin
  Result := TNewRadioButton.Create(WizardForm);
  with Result do
    begin
      Parent := AParent;
      Checked := AChecked;
      Width := AWidth;
      Left := ALeft;
      Top := ATop;
      Font.Size := AFontSize;
      Font.Style := AFontStyle;
      Caption := ACaption;
    end;
end;

我有 2 个自定义页面,其中我必须在左侧显示我的图像,在右侧显示一些文本和单选按钮(每页 2 个单选按钮)。 所以,在我的 InitializeWizard 过程中,我写了这个:

wpSelectInstallTypePage := CreateCustomPage(wpSelectDir, 'Caption', 'Description');
rbStandardInstallType := CreateRadioButton(WizardForm.InnerPage, True, WizardForm.InnerPage.Width, ScaleX(15), WizardForm.MainPanel.Top + ScaleY(30), 9, [fsBold], 'Standard');
rbCustomInstallType := CreateRadioButton(WizardForm.InnerPage, False, rbStandardInstallType.Width, rbStandardInstallType.Left, rbStandardInstallType.Top + rbStandardInstallType .Height + ScaleY(16), 9, [fsBold], 'Custom');

wpMSSQLInstallTypePage := CreateCustomPage(wpSelectInstallTypePage.ID, 'Caption2', 'Description2');
rbDefaultMSSQLInstance := CreateRadioButton(WizardForm.InnerPage, True, WizardForm.InnerPage.Width, ScaleX(15), WizardForm.MainPanel.Top + ScaleY(30), 9, [fsBold], 'DefaultInstance');
rbNamedMSSQLInstance := CreateRadioButton(WizardForm.InnerPage, False, rbDefaultMSSQLInstance.Width, rbDefaultMSSQLInstance.Left, rbDefaultMSSQLInstance.Top + rbDefaultMSSQLInstance.Height + ScaleY(10), 9, [fsBold], 'NamedInstance');

最后,这是我的 CurPageChanged 代码,以便正确显示所有控件:

procedure CurPageChanged(CurPageID: Integer);
  begin
    case CurPageID of
      wpSelectInstallTypePage.ID, wpMSSQLInstallTypePage.ID:
          WizardForm.InnerNotebook.Visible := False;  
    else
      WizardForm.InnerNotebook.Visible := True;
    end;
    rbDefaultMSSQLInstance.Visible := CurPageID = wpMSSQLInstallTypePage.ID;
    rbNamedMSSQLInstance.Visible := CurPageID = wpMSSQLInstallTypePage.ID;
    rbStandardInstallType.Visible := CurPageID = wpSelectInstallTypePage.ID;
    rbCustomInstallType.Visible := CurPageID = wpSelectInstallTypePage.ID;
  end

您将单选按钮添加到错误的父控件 (WizardForm.InnerPage)。不是您正在创建的自定义页面。然后,您可以通过显式 hiding/showing CurPageChanged.

中的单选按钮来解决该缺陷

由于所有四个单选按钮都有相同的父级 (WizardForm.InnerPage),因此只能选中其中一个。因此,当您选中 rbDefaultMSSQLInstance 时,rbStandardInstallType 隐式未选中。


正确代码见:

(确保删除多余的 CurPageChanged 代码)


您还应该考虑使用 CreateInputOptionPage 而不是手动将单选按钮添加到通用自定义页面。