3

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?

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327

1 Answers1

7

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;
Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • Well, then you're using a wrong event. If you want to prevent the installer to even start you should use the `InitializeSetup` event method. In all cases, this answer is a wrong way. – TLama Feb 13 '14 at 00:11
  • @TLama This isn't the very first thing, I want this to happen after the welcome page. I never wanted to prevent the wizard from starting, or I would have put it in `InitializeSetup`. – Jerry Dodge Feb 13 '14 at 00:15
  • @TLama Actually since I posted this question/answer, I changed the logic and now there's even a page in the wizard asking if they'd like to check for a new version. – Jerry Dodge Feb 13 '14 at 00:16
  • You've said "at the very first step" and that means before the wizard starts. And I agree with the idea to not even start the setup if there's a newer version. But I see, you've got your own way which you want to offer to your users. Good luck then ;-) – TLama Feb 13 '14 at 00:22
  • @TLama Yeah, that statement was very loosely defined :-) – Jerry Dodge Feb 13 '14 at 00:40