【问题标题】:Inno Setup Create dependency between custom check boxesInno Setup 创建自定义复选框之间的依赖关系
【发布时间】:2015-09-28 15:57:22
【问题描述】:

我有一个自定义页面SelectPage,我正在其上创建两个自定义复选框。来自InitializeWizard程序的相关部分代码如下:

//Define the Restart Services Checkbox
  RestartServicesCheckBox := TNewCheckBox.Create(WizardForm);
  with RestartServicesCheckBox do
    begin
      Parent := SelectPage.Surface;
      Caption := 'Restart Services';
      Left := OptionsLabel.Left;
      Top := OptionsLabel.Top + ScaleY(20);
      Checked := True;
    end;
//Define the Restart Server Checkbox
  RestartServerCheckBox := TNewCheckBox.Create(WizardForm);
  with RestartServerCheckBox do
    begin
      Parent := SelectPage.Surface;
      Caption := 'Restart Server';
      Left := OptionsLabel.Left;
      Top := RestartServicesCheckBox.Top + ScaleY(22);
      Checked := False
    end;

这很有效,我得到了我想要的复选框,它们执行我分配给它们的操作。我正在努力解决的是如何在两者之间分配依赖关系,以便如果选中一个,则自动取消选中另一个。但是,我不想要单选按钮类型依赖项,因为可能需要取消选中两个复选框。我正在考虑尝试拦截 OnClick 事件,如下所示:

var
  DefaultOnClick: TNotifyEvent;

procedure InitializeWizard();
begin
//Store the original OnClick event procedure and assign custom procedure
  DefaultOnClick := WizardForm.TCheckBox.OnClick;
  WizardForm.TCheckBox.OnClick := @OnClick;
end;

//Uncheck and Restart Services if Restart Server is checked and vice versa
procedure UpdateOptions();
begin
  with RestartServicesCheckBox do
    begin
      if RestartServicesCheckBox.Checked then
        begin
          Checked := False;
        end;
    end;
  with RestartServerCheckBox do
    begin
      if RestartServerCheckBox.Checked then
        begin
          Checked := False;
        end;
    end;
end;

//Update the options check boxes if the states change and restore the original event handler procedures
procedure OnClick(Sender: TObject);
begin
  DefaultOnClick(Sender);
  UpdateOptions;
end;

但是,我不知道我需要拦截的完整事件名称是什么。无论如何,它显然不是WizardForm.TCheckBox.OnClick。这个事件的名称是什么,这个方法会起作用吗?或者,有没有更简单的方法来做到这一点?

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:

    这是您需要使用的TCheckBox.OnClick 事件。

    var
      RestartServicesCheckBox: TNewCheckBox;
      RestartServerCheckBox: TNewCheckBox;
    
    procedure RestartServicesCheckBoxClick(Sender: TObject);
    begin
      if RestartServicesCheckBox.Checked then
        RestartServerCheckBox.Checked := False;
    end;
    
    procedure RestartServerCheckBoxClick(Sender: TObject);
    begin
      if RestartServerCheckBox.Checked then
        RestartServicesCheckBox.Checked := False;
    end;
    
    procedure InitializeWizard();
    begin
      // Define the Restart Services Checkbox
      RestartServicesCheckBox := TNewCheckBox.Create(WizardForm);
      with RestartServicesCheckBox do
      begin
        ...
        Checked := True;
        OnClick := @RestartServicesCheckBoxClick;
      end;
    
      // Define the Restart Server Checkbox
      RestartServerCheckBox := TNewCheckBox.Create(WizardForm);
      with RestartServerCheckBox do
      begin
        ...
        Checked := False;
        OnClick := @RestartServerCheckBoxClick;
      end;
    end;
    

    虽然我认为三个单选按钮可能会更好:

    • 不要重启
    • 仅重启服务
    • 重启服务器

    【讨论】:

    • 谢谢马丁。这正是我需要知道的。单选按钮通常在这种情况下会很好,但是第三个选项,什么都不做(不重新启动任何东西)意味着不明显(即不作为一个选项宣传),因为它只需要在极少数情况下使用,因此使用复选框的原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多