4
votes

I have some declarations at the [Dirs]-section in my Inno Setup file. I use "Inno Setup Compiler" and a normal text editor (Notepad++) for developing. When I cancel the setup before choosing the install directory, the {app} variable is empty for sure. I get this error (which is totally logic):

How can I fix that no error occurs after pressing the "Cancel" button and committing that I want to cancel the setup?

Internal error: An attempt was made to expand the "app" constant before it was initialized.

Can I globally set the {app} variable or give it a default value?

Here is a code snippet where I use the variable {app}:

[Dirs]
Name: {app}; Permissions: everyone-readexec
Name: {app}\bin; Permissions: everyone-readexec

[Run]
Filename: "{app}\run.exe; Flags: runhidden

[INI]
Filename: {app}\bin\myIni.ini; Section: Settings;

[InstallDelete]
Name: {app}\*; Type: filesandordirs; Tasks: 

Thanks for help, regards, C.

2
It would be helpful if your question was edited to include the relevant section of the source code. It would also be helpful to know what specific software you are using. - ben rudgers

2 Answers

6
votes

Either you should skip the code, which attempts to expand the {app} constant before it's initialized, or as a workaround you can use the WizardDirValue, which actually returns value to the {app} when it's being expanded. Even reference mentions that (emphasized by me):

Returns the current contents of the edit control on the Select Destination Location page of the wizard.

Unlike ExpandConstant('{app}'), this function will not fail if called after the wizard is shown but prior to the user selecting a directory. Rather, it will return the default directory name.

In the most recent source code you can see how the {app} constant is expanded on this line.

0
votes

Thanks for helping, the problem got solved!

Before the user reaches the 'Select Destination Location' the {app} variable is not set. My DeInitialize-Procedure looked like this:

procedure DeinitializeSetup();
var
  SettingsPath: String;
begin   
    SettingsPath := ExpandConstant('{app}')
    DelTree(SettingsPath + '\bin', True, True, True);
end;

What I did is I created a Boolean variable at the beginning:

[Code]
var appIsSet: Boolean;

I set it to false at initializing:

function InitializeSetup(): Boolean;
begin
//    interesting code
appIsSet := False;
end;

... and set it to 'true' after the user has reached 'wpSelectDir' in nextButtonClick (see code snippet below:)

begin
if CurPageID = wpSelectDir then
begin
    appIsSet := True;

The last step is to check in the Deinitialize-Procedure if the boolean variable is set. If so, he can access on it, if not - do nothing:

procedure DeinitializeSetup();
var
    SettingsPath: String;
begin
if appIsSet then begin
    SettingsPath := ExpandConstant('{app}')
    DelTree(SettingsPath + '\bin', True, True, True);
end;
end;