Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change AppID using [Code] just before the installation in Inno Setup

In a setup I give the user the option to install either a 32 or 64 bit version using radio buttons.

I then want to append either _32 or _64 to the AppId.

I know I can change the AppId using scripted constants but the needed function is called while Setup is starting. But at this point the radio buttons do not yet exist and thus I receive the error "Could not call proc".

I consulted the Inno Setup help and I read that you can change the AppId at any given point before the installation process has started (if I understood correctly).

So how do I manage to do this?

I am looking forward to your answers!

like image 272
user1662035 Avatar asked Apr 14 '13 21:04

user1662035


1 Answers

Some of the {code:...} functions for certain directive values are called more than one time and the AppId is one of them. To be more specific, it is called twice. Once before a wizard form is created and once before the installation starts. What you can do is just to check if the check box you're trying to get the value from exists. You can simply ask if it's Assigned like follows:

[Setup]
AppId={code:GetAppID}
...

[Code]
var  
  Ver32RadioButton: TNewRadioButton;
  Ver64RadioButton: TNewRadioButton;

function GetAppID(const Value: string): string;
var
  AppID: string;
begin
  // check by using Assigned function, if the component you're trying to get a
  // value from exists; the Assigned will return False for the first time when
  // the GetAppID function will be called since even WizardForm not yet exists
  if Assigned(Ver32RadioButton) then
  begin
    AppID := 'FDFD4A34-4A4C-4795-9B0E-04E5AB0C374D';
    if Ver32RadioButton.Checked then
      Result := AppID + '_32'
    else
      Result := AppID + '_64';
  end;
end;

procedure InitializeWizard;
var
  VerPage: TWizardPage;
begin
  VerPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');
  Ver32RadioButton := TNewRadioButton.Create(WizardForm);
  Ver32RadioButton.Parent := VerPage.Surface;
  Ver32RadioButton.Checked := True;
  Ver32RadioButton.Caption := 'Install 32-bit version';
  Ver64RadioButton := TNewRadioButton.Create(WizardForm);
  Ver64RadioButton.Parent := VerPage.Surface;
  Ver64RadioButton.Top := Ver32RadioButton.Top + Ver32RadioButton.Height + 4;
  Ver64RadioButton.Caption := 'Install 64-bit version';
end;
like image 178
TLama Avatar answered Sep 30 '22 07:09

TLama