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

只愿长相守 提交于 2019-12-20 02:56:18

问题


I'm creating an Installer using Inno Setup. I have to take two paths from user. One for program executables and another for libs. The default app folder is {pf}/companyname/applicationname

In the InitializeWizard I have created second page which takes the lib folder from the user.

Is there any way to change the default lib folder to the user selected folder {app}?

I have tried WizardDirValue. It just gives the default {app} value and NOT the path which user selected in first page.

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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4638306/how-to-show-use-the-user-selected-app-path-app-in-inputdirpage-in-inno-setup

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