Inno Setup:如果选择了另一个组件,如何自动选择一个组件? [英] Inno Setup: how to auto select a component if another component is selected?

查看:137
本文介绍了Inno Setup:如果选择了另一个组件,如何自动选择一个组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,只有在还安装了特定组件的情况下,才必须安装.但我也允许自定义安装.因此,如果还检查了特定组件,则需要自动检查该组件(反之亦然,如果另一个组件未启用,则禁用它).我知道我可以简单地将文件本身附加到特定组件,但是我想向用户提供有关已安装此先决条件的反馈.

I've a file the must be installed only if a specific component is also installed. But I also allow custom install. So there is the need to auto-check the component if a specific component is also checked (and vice versa, disable if the other component is not enabled). I know I can simply attach the file itself to the specific component, but I want to provide to user the feedback about this prerequisite being installed.

因此,简短版本:如何基于检查组件'B'的状态来自动检查组件'A'?

推荐答案

一种简单的实现,用于检查B(如果选中了A):

A simple implementation for checking B, if A is checked:

[Components]
Name: "A"; Description: "A"
Name: "B"; Description: "B"

[Code]

var
  PrevItemAChecked: Boolean;
  TypesComboOnChangePrev: TNotifyEvent;
  ComponentsListClickCheckPrev: TNotifyEvent;

procedure ComponentsListCheckChanges;
begin
  if PrevItemAChecked <> WizardIsComponentSelected('A') then
  begin
    if WizardIsComponentSelected('A') then
      WizardSelectComponents('B');

    PrevItemAChecked := WizardIsComponentSelected('A');
  end;
end;

procedure ComponentsListClickCheck(Sender: TObject);
begin
  { First let Inno Setup update the components selection }
  ComponentsListClickCheckPrev(Sender);
  { And then check for changes }
  ComponentsListCheckChanges;
end;

procedure TypesComboOnChange(Sender: TObject);
begin
  { First let Inno Setup update the components selection }
  TypesComboOnChangePrev(Sender);
  { And then check for changes }
  ComponentsListCheckChanges;
end;

procedure InitializeWizard();
begin
  { The Inno Setup itself relies on the TypesCombo.OnChange and OnClickCheck. }
  { so we have to preserve their  handlers. }

  ComponentsListClickCheckPrev := WizardForm.ComponentsList.OnClickCheck;
  WizardForm.ComponentsList.OnClickCheck := @ComponentsListClickCheck;

  TypesComboOnChangePrev := WizardForm.TypesCombo.OnChange;
  WizardForm.TypesCombo.OnChange := @TypesComboOnChange;

  { Remember the initial state }
  { (by now the components are already selected according to }
  { the defaults or the previous installation) }
  PrevItemAChecked := WizardIsComponentSelected('A');
end;

该代码要求 WizardIsComponentSelected WizardSelectComponents (有关没有这些功能的代码版本,请参见回答历史记录)

The code requires Inno Setup 6 for WizardIsComponentSelected and WizardSelectComponents (for a version of the code without those functions, see the answer history)

以上内容基于 Inno Setup ComponentsList OnClick事件.

这篇关于Inno Setup:如果选择了另一个组件,如何自动选择一个组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆