skr
skr

Reputation: 1811

Inno Setup: How to use user inputs to execute codes conditionally

The below code asks user to select Yes or No using CreateInputOptionPage, with the below code I want to prompt message "Yes selected" if user selects "Yes" if user selects no then prompt "No selected".

My code doesn't seem to work. Please help.

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DisableProgramGroupPage=yes
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=D:\authorized\Builds\Custom wizard

[Code]
//#include "Solo - detectVersionFInal.iss"
var
  UsagePage: TInputOptionWizardPage;
  InstallationTypeIsClient: boolean;
  Initialize:boolean;
procedure InitializeWizard;
begin
  { Create the pages }
    UsagePage := CreateInputOptionPage(wpWelcome,
    'KMOffline setup information', 'How would you like to install KMOffline?',
    'Would you like to insall KMOffline as a service?.',
    True, False);
  UsagePage.Add('Yes');
  UsagePage.Add('No');
  UsagePage.Values[0] := False;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin                                                                                    
  if CurPageID=UsagePage.ID then
  begin
    InstallationTypeIsClient := UsagePage.Values[0];
    MsgBox('InstallationTypeIsClient value is ' + Format('%d', [InstallationTypeIsClient]), mbInformation, MB_OK);
  end;
Result := True;
end;

function InitializeSetup: Boolean;
var
  begin
if (InstallationTypeIsClient=True) then
        begin
          MsgBox('Yes selected' + Format('%d', [InstallationTypeIsClient]), mbInformation, MB_OK);
        end;
             if (InstallationTypeIsClient=False) then
        begin
          MsgBox('No selected ' + Format('%d', [InstallationTypeIsClient]), mbInformation, MB_OK);
        end;
  Result := True;
end;

Upvotes: 0

Views: 480

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202272

Just move your code from InitializeSetup to NextButtonClick:

function NextButtonClick(CurPageID: Integer): Boolean;
begin                                                                                    
  if CurPageID = UsagePage.ID then
  begin
    if UsagePage.Values[0] then
    begin
      MsgBox('Yes selected', mbInformation, MB_OK);
    end
      else
    begin
      MsgBox('No selected', mbInformation, MB_OK);
    end;
  end;
  Result := True;
end;

Upvotes: 2

Related Questions