Search code examples
inno-setuppascalscript

Inno Setup event that is generated when folder is browsed on TInputDirWizardPage?


I'm using a custom TInputDirWizardPage to input three different target folders for my installation.

When the first folder is changed, I'd like to automatically change the 3rd folder's path. Is it possible to create an event that occurs when the Browse button is used for the first folder and a specific folder is selected? If so, is it also possible to change the 3rd folder's path programmatically?


Solution

  • You can override TInputDirWizardPage.Buttons[0].OnClick event handler:

    var
      DirPage: TInputDirWizardPage;
      PrevFirstButtonClick: TNotifyEvent;
    
    procedure FirstButtonClick(Sender: TObject);
    var
      PrevValue: string;
    begin
      PrevValue := DirPage.Values[0];
    
      { Call remembered handler }
      PrevFirstButtonClick(Sender);
    
      if DirPage.Values[0] <> PrevValue then
      begin
        { And do whatever you want to do when the value changes }
        MsgBox(Format('Value changed from "%s" to "%s".', [PrevValue, DirPage.Values[0]]),
          mbInformation, MB_OK);
      end;
    end;
    
    procedure InitializeWizard();
    begin
      DirPage := CreateInputDirPage(
        wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', False, '');
      { add directory input page items }
      DirPage.Add('Path to Apache:');
      DirPage.Add('Path to PHP:');
      DirPage.Add('Path to Server Files:');
    
      { Remember the standard handler }
      PrevFirstButtonClick := DirPage.Buttons[0].OnClick;
      { And assign our override } 
      DirPage.Buttons[0].OnClick := @FirstButtonClick;
    end;
    

    The code needs Unicode version of Inno Setup. Calling DirPage.Buttons[0].OnClick strangely does not work in Ansi version.