Inno Setup:如何使用用户输入有条件地执行代码

时间:2018-07-09 18:16:08

标签: inno-setup

以下代码要求用户使用CreateInputOptionPage选择是或否,如果用户选择“是”,则下面的代码要提示消息“是已选择”,如果用户选择“否”,则提示“未选择”。

我的代码似乎无效。请帮忙。

[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;

1 个答案:

答案 0 :(得分:2)

只需将您的代码从InitializeSetup移至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;