Inno Setup在自定义复选框

时间:2015-09-28 15:57:22

标签: inno-setup pascalscript

我有一个自定义页面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。这个事件的名称是什么,这个方法会起作用吗?或者,有更简单的方法吗?

1 个答案:

答案 0 :(得分: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;

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

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