How to show/use the user selected app path {app} in InputDirPage in Inno Setup?

纵然是瞬间 提交于 2019-12-02 01:21:31

As the name InitializeWizard() shows you it is an initialization function, called only once, before the wizard is shown. You can test this yourself by setting a breakpoint on your code - it will be hit only once, right at the start.

It's therefore the correct place to add a new wizard page and set the default value of any control, but it's impossible to react on changes to other wizard pages. What you need to do is to update the library path right before your page is shown. The correct way to do this is the NextButtonClick() function. Here is some sample code:

var
  LibPage: TInputDirWizardPage;

procedure InitializeWizard();
begin
  LibPage := CreateInputDirPage(wpSelectDir, 'Select Library Location',
    'Where should the library files be stored?',
    'To continue, click Next. If you would like to select a different folder, ' +
    'click Browse.', False, 'Libs');
  LibPage.Add('');
  LibPage.Values[0] := WizardDirValue + '\libs';
end;

This will add your page right after the page that queries the {app} directory. Since the user can click the "Prev" button to change the {app} directory multiple times you should always update the library path when your page is about to be shown:

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = wpSelectDir then
    LibPage.Values[0] := WizardDirValue + '\libs';
end;

For better usability you could also check that the library directory is the default value, and otherwise don't change its value.

You can use the ExpandConstant function. In it, all Inno Setup constants are replaced with their real values. For example, ExpandConstant('{app}\mydir') should become C:\Program Files\\mydir.

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