Inno设置MsgBox有三个按钮和三个结果

时间:2014-08-26 21:42:19

标签: inno-setup pascalscript

我正在尝试创建一个带有三个按钮和三个结果的MsgBox,但我无法看到如何创建第三个结果?我目前有两个按钮MsgBox的代码,完美无缺:

if ((strExistingInstallPath <> '') and (strExistingVersion = '2.5.3')) then
begin
  if SuppressibleMsgBox('Setup has detected that ' + strMyAppName + ' ' + strExistingVersion + '.' + strExistingBuild + ' is installed.' + #13#10 + #13#10 +
    'The existing version must be removed before installing or upgrading to ' + strMyAppVersion + '.' + strMyAppBuild + '.' + #13#10 + #13#10 +
    'Would you like Setup to uninstall the existing version?',
    mbConfirmation, MB_YESNO, IDYES) = IDYES then
    begin
      Exec(GetUninstallString, '', '', SW_SHOW,
        ewWaitUntilTerminated, intResultCode);
      Result := True;
    end else
      begin
        MsgBox('The existing version must be removed first.' + #13#10 +
          'Setup is unable to continue. Setup will now exit.',
          mbError, MB_OK);
        Result := False;
      end;
end;

如果我将MB_YESNO更改为MB_YESNOCANCEL,我现在可以获得三个按钮,取消。但是,由于if语句已分配给MsgBox,因此我很难弄清楚如何执行else if IDCANCEL then类型语句。我试图将MsgBox返回的ID常量分配给一个字符串,然后为该字符串创建单独的if语句,使其等于每个ID常量,但这很难失败。我在这里错过了什么?理想情况下,我希望将三个按钮标记为无声,以便第三个按钮可以被赋予{{1用于阻止卸载提示的参数。那么,是否可以重命名按钮?

2 个答案:

答案 0 :(得分:6)

您可以编写多个if语句,但是您必须将返回的值存储到变量中并检查该变量值。但是正如@Sertac在他的评论中提到的,你可以使用case语句,更好地描述代码中的目标,例如:

case SuppressibleMsgBox('Text', mbConfirmation, MB_YESNOCANCEL, IDYES) of
  IDYES:
  begin
    { user pressed Yes }
  end;
  IDNO:
  begin
    { user pressed No }
  end;
  IDCANCEL:
  begin
    { user pressed Cancel }
  end;
end;

出于对多个if陈述的好奇心,可能是:

var
  MsgResult: Integer;
begin
  MsgResult := SuppressibleMsgBox('Text', mbConfirmation, MB_YESNOCANCEL, IDYES);

  if MsgResult = IDYES then
  begin
    { user pressed Yes }
  end
  else
  if MsgResult = IDNO then
  begin
    { user pressed No }
  end
  else
  if MsgResult = IDCANCEL then
  begin
    { user pressed Cancel }
  end;
end;

答案 1 :(得分:1)

以下是最终代码,以防其他人使用:

var
  intMsgBoxResult: Integer;
if ((strExistingInstallPath <> '') and (strExistingVersion = '2.5.3')) then
begin
  intMsgBoxResult := SuppressibleMsgBox('Setup has detected that ' + strMyAppName + ' ' + strExistingVersion + '.' + strExistingBuild + ' is installed.' + #13#10 + #13#10 +
    'The existing version must be removed before installing or upgrading to ' + strMyAppVersion + '.' + strMyAppBuild + '.' + #13#10 + #13#10 +
    'Would you like Setup to uninstall the existing version?',
    mbConfirmation, MB_YESNO, IDIGNORE);
  if intMsgBoxResult = IDYES then
    begin
      Exec(GetUninstallString, '/silent', '', SW_SHOW,
        ewWaitUntilTerminated, intResultCode);
      Result := True;
    end;
  if intMsgBoxResult = IDNO then 
    begin
      MsgBox('The existing version must be removed first.' + #13#10 +
        'Setup is unable to continue. Setup will now exit.',
        mbError, MB_OK);
      Result := False;
    end;
  if intMsgBoxResult = IDIGNORE then
    begin
      Exec(GetUninstallString, '', '', SW_SHOW,
        ewWaitUntilTerminated, intResultCode);
      Result := True;
    end; 
end;