InnoSetup:自定义设置类型 - 如果用户既未选择任何组件,则显示消息?

时间:2014-04-27 12:21:37

标签: types components inno-setup

我正在编写包含以下部分的InnoSetup安装程序:

[Types]
Name: "ChooseVers"; Description: "Install support for WordPerfect versions:"; Flags: iscustom

[Components]
Name: "InstallForWP51"; Description: "Install support for WordPerfect 5.1"; Types: ChooseVers; Flags: checkablealone
Name: "InstallForWP62"; Description: "Install support for WordPerfect 6.2"; Types: ChooseVers; Flags: checkablealone

当用户运行安装程序时,它会为“组件”下列出的两个项目提供两个复选框,用户可以选中其中一个或两个。

如果用户没有选中任何一个框,我想要做的就是显示一条消息,这样就不会安装任何内容。就目前而言,用户只是看到一个有点误导性的消息,列出将要执行的操作列表下的任何内容,然后安装程序关闭。这没有什么严重的错误,但提供更多信息会更好。

我非常感谢你对此有任何帮助。

1 个答案:

答案 0 :(得分:3)

您可以使用IsComponentSelected功能检查是否选择了组件。对于验证可能很适合使用NextButtonClick事件方法,它允许您留在页面上。在下面的脚本中显示了如果没有选择任何组件,如何显示确认消息框,并允许用户留在页面上或继续:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Types]
Name: "ChooseVers"; Description: "Install support for WordPerfect versions:"; Flags: iscustom

[Components]
Name: "InstallForWP51"; Description: "Install support for WordPerfect 5.1"; Types: ChooseVers; Flags: checkablealone
Name: "InstallForWP62"; Description: "Install support for WordPerfect 6.2"; Types: ChooseVers; Flags: checkablealone

[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;
  if (CurPageID = wpSelectComponents) and not (IsComponentSelected('InstallForWP51') or
    IsComponentSelected('InstallForWP62')) then
  begin
    Result := MsgBox('None of the components is selected. This won''t install ' +
      'anything. Are you sure you want to continue ?', mbConfirmation, MB_YESNO) = IDYES;
  end;
end;

或相同的缩写为不太可读的形式:

[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := (CurPageID <> wpSelectComponents) or (IsComponentSelected('InstallForWP51') or
    IsComponentSelected('InstallForWP62')) or (MsgBox('None of the components is selected. ' +
    'This won''t install anything. Are you sure you want to continue ?', mbConfirmation,
    MB_YESNO) = IDYES);
end;