Saving a file retrieved with InputFilePage

42 views
Skip to first unread message

Jorge Moraleda

unread,
May 1, 2024, 7:32:58 PMMay 1
to innosetup
The sample code below is supposed to ask for a file location in wizard page GetSettingsPage of type TInputFileWizardPage and then save that file in the [Files] section.

I thought using
Flags: external would allow me to use a scripted constant to achieve this. But it appears that GetInputFileLocation gets called before InitializeWizard, because I get an error "Line 15: Could not call proc" and GetSettingsPage is nil.

What am I doing wrong? Thank you.

------------ Complete test code below

[Setup]
AppName=Test
AppVerName=Test
DefaultDirName={userpf}\Test

[Files]
Source: {code:GetInputFileLocation}; DestDir: {app}; DestName:settings.yaml; Flags: external;

[Code]
var
  GetSettingsPage: TInputFileWizardPage;

function GetInputFileLocation(Param: String): String;
begin
  Result := GetSettingsPage.Values[0];
end;

procedure InitializeWizard;
begin
  GetSettingsPage := CreateInputFilePage(wpSelectDir, 'Title', 'Msg', 'Submsg');
  // Add one input field
  GetSettingsPage.Add('Label', 'All files (*.*)|*.*', '*.*');  
end;

Jorge Moraleda

unread,
May 1, 2024, 9:52:40 PMMay 1
to innosetup
Answering my own question:

I had to test for "nil" in "GetInputFileLocation":

    if GetSettingsPage <> nil then
      Result := GetSettingsPage.Values[0];


When the function is called "for real" in the phase of writing the files "GetSettingsPage" exists and  the function returns the correct value. And when it gets called in the earlier phases, it does not matter what it returns.

Gavin Lambert

unread,
May 2, 2024, 1:45:18 AMMay 2
to innosetup
On Thursday, May 2, 2024 at 1:52:40 PM UTC+12 Jorge Moraleda wrote:
When the function is called "for real" in the phase of writing the files "GetSettingsPage" exists and  the function returns the correct value. And when it gets called in the earlier phases, it does not matter what it returns.

You can disable the call on startup by specifying an ExternalSize (e.g. ExternalSize: 0; or use a more realistic value if you know it to improve the Components page).  It may still end up being called more than once later in the installation process, however.

Jorge Moraleda

unread,
May 4, 2024, 10:31:43 AMMay 4
to innosetup
Thank you. I confirm this works too.
Reply all
Reply to author
Forward
0 new messages