1

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Steve
  • 2,510
  • 4
  • 34
  • 53

1 Answers1

3

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • If I set DirPage.Values[0] it'll change the contents of the edit box? – Steve Dec 16 '18 at 01:18
  • I've tried and this code doesn't work for me. Clicking the Browse button for the first button doesn't do any action. – Steve Dec 17 '18 at 17:04
  • It works, if I copy and paste the code to a blank .iss file. If it does not work for you, you probably have some other code that conflicts with it. Please show us [mcve]. – Martin Prikryl Dec 17 '18 at 19:48
  • I've tried creating an empty iss file and it doesn't work for me. I'm using an older version of inno 5.5.3. I'll try to install a brand new copy on another computer and see if it works like that. – Steve Dec 17 '18 at 20:30
  • 1
    OK, I've found out that the code indeed does not work in Ansi version of Inno Setup. It looks like a bug. But you should be using Unicode version anyway. – Martin Prikryl Dec 19 '18 at 07:20
  • @MartinPrikryl Thanks for the help and for the sample code! it really worked! – Максим Румянцев Sep 13 '19 at 08:43