How to properly close out of Inno Setup wizard without prompt?

守給你的承諾、 提交于 2019-12-11 05:31:05

问题


Part of my installer checks for a latest version on our server and downloads automatically if necessary, just after the welcome page. The actual check and download are in a function CheckForNewInstaller which returns True if new installer was downloaded and has executed, and False if it needs to continue. If the new installer was downloaded (True) then the wizard needs to shut down.

Using the following code, I have done this using WizardForm.Close. However, it still prompts the user if they're sure they wish to cancel. In normal scenarios, I still want the user to get this prompt if they attempt to close the installer. However, I need to suppress this dialog when I need to forcefully close the wizard. I also cannot be terminating the process, because the cleanup process wouldn't happen properly.

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ResultCode: Integer;
  X: Integer;
begin
  Log('NextButtonClick(' + IntToStr(CurPageID) + ') called');
  Result := True;
  case CurPageID of
    wpWelcome: begin
      if CheckForNewInstaller then begin
        //Need to close this installer as new one is starting
        WizardForm.Close;
      end;
    end;
    ....
  end;
end;

How can I close this installer completely down without any further user interaction?


回答1:


This can be done by handling the CancelButtonClick event and setting the Confirm parameter...

var
  ForceClose: Boolean;

procedure Exterminate;
begin
  ForceClose:= True;
  WizardForm.Close;  
end;

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
  Confirm:= not ForceClose;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ResultCode: Integer;
  X: Integer;
begin
  Log('NextButtonClick(' + IntToStr(CurPageID) + ') called');
  Result := True;
  case CurPageID of
    wpWelcome: begin
      if CheckForNewInstaller then begin
        Exterminate;
      end;
    end;
    ....
  end;
end;


来源:https://stackoverflow.com/questions/21737462/how-to-properly-close-out-of-inno-setup-wizard-without-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!