Inno Setup:将独家任务变成单选框

时间:2018-08-15 09:07:54

标签: installation windows-installer inno-setup

我正在开发一个具有4个单选框的Inno Setup安装程序,以便用户选择他们要安装的“风味”。文档使我感到困惑。我应该为此使用“任务”,“类型”还是“组件”?

似乎任务具有内置的单选按钮行为:设置exclusive标志时,一次只能选择一个任务。那正是我想要的。所以我有这段代码:

[Tasks]
Name: variant-a; Description: "A"; GroupDescription: "Variant"; Flags: exclusive
Name: variant-b; Description: "B"; GroupDescription: "Variant"; Flags: exclusive unchecked
Name: variant-c; Description: "C"; GroupDescription: "Variant"; Flags: exclusive unchecked
Name: variant-d; Description: "D"; GroupDescription: "Variant"; Flags: exclusive unchecked

如何显示单选按钮?以及如何获得所选任务的值(例如"variant-a")?

1 个答案:

答案 0 :(得分:3)

最好是使用现有脚本并查看其工作原理

  

文档使我感到困惑;我应该使用任务,类型还是   组件呢?

添加的代码部分同时具有:任务和组件 因此,请确定对您的项目更有用的内容。

examples目录中有许多非常有用的示例,非常适合响应用户输入。

  • 将..:... \ Inno Setup 5 \ Examples \ CodeExample1.iss复制到CodeExample1_ex.iss。
  • 打开复制的文件并插入以下代码片段。

搜索 OutputDir=userdocs:Inno Setup Examples Output

在下面插入

//OutputDir=userdocs:Inno Setup Examples Output

[Tasks]
Name: variant_a; Description: "A"; GroupDescription: "Variant"; Components: main\a; Flags: exclusive
Name: variant_b; Description: "B"; GroupDescription: "Variant"; Components: main\b; Flags: exclusive unchecked
Name: variant_c; Description: "C"; GroupDescription: "Variant"; Components: main\c; Flags: exclusive unchecked
Name: variant_d; Description: "D"; GroupDescription: "Variant"; Components: main\d; Flags: exclusive unchecked

; Disabled we need it later -----------------------------------------------------
;Name: variant_a; Description: "A"; GroupDescription: "Variant"; Flags: exclusive
;Name: variant_b; Description: "B"; GroupDescription: "Variant"; Flags: exclusive unchecked
;Name: variant_c; Description: "C"; GroupDescription: "Variant"; Flags: exclusive unchecked
;Name: variant_d; Description: "D"; GroupDescription: "Variant"; Flags: exclusive

[Types]
Name: "full"; Description: "Full installation"
Name: "compact"; Description: "Compact installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom

[Components]
Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed
Name: "help"; Description: "Help File"; Types: full
Name: "readme"; Description: "Readme File"; Types: full
Name: "readme\en"; Description: "English"; Flags: exclusive
Name: "readme\de"; Description: "German"; Flags: exclusive
Name: "main"; Description: "variants"; Types: custom
Name: "main\a"; Description: "variant_a"; Types: custom; Flags: exclusive
Name: "main\b"; Description: "variant_b"; Types: custom; Flags: exclusive
Name: "main\c"; Description: "variant_c"; Types: custom full; Flags: exclusive
Name: "main\d"; Description: "variant_d"; Types: custom; Flags: exclusive

搜索[代码]并添加I : integer;

[Code]
var
  MyProgChecked: Boolean;
  MyProgCheckResult: Boolean;
  FinishedInstall: Boolean;
  I : integer;

搜索 procedure CurPageChanged(CurPageID: Integer);

在下面插入

//procedure CurPageChanged(CurPageID: Integer);
var
Addtxt,WFCaption,WSelCaption : String;

搜索 Log('CurPageChanged(' + IntToStr(CurPageID) + ') called');

在下面插入

      //Log('CurPageChanged(' + IntToStr(CurPageID) + ') called');

  if CurPageID = wpSelectComponents then begin
     WFCaption := WizardForm.ComponentsList.ItemCaption[8];
     Addtxt    := ' <---------- If I where you I would take this';
     if Pos(Addtxt,WFCaption) = 0 then WizardForm.ComponentsList.ItemCaption[8] := WFCaption + Addtxt;
  end;

  if CurPageID = wpSelectTasks then
  begin
     { Only now is the TasksList populated }
     if WizardForm.TasksList.Items.Count = 2 then begin
        WSelCaption := Copy(WizardForm.TasksList.ItemCaption[1],1,2); //else 
        if Pos('C',WizardForm.TasksList.ItemCaption[1]) > 0 then 
           WSelCaption := WSelCaption + ' <-------- Your choice, my favorite, thank you :-)'#13#10+
                                        '                  Not correct? Please go back and change the selection'   else
           WSelCaption := WSelCaption + ' <-------- Your choice : Not correct? Please go back and change the selection';
        WizardForm.TasksList.ItemEnabled[0] := False;
        WizardForm.TasksList.ItemCaption[1] := WSelCaption;
     end else begin
        For I := 1 to WizardForm.TasksList.Items.Count -1 do begin
         if WizardForm.TasksList.Checked[I] then begin
            WizardForm.TasksList.ItemCaption[I] := Copy(WizardForm.TasksList.ItemCaption[I],1,2) +
                                      ' <-------- Your choice : Not correct? Please change the selection';
         end;
        end; // for 
     end;
   end;

接下来是用于CurPageID

的常量

示例:

  if CurPageID = wpSelectComponents  then begin
  

wpWelcome,wpLicense,wpPassword,wpInfoBefore wpUserInfo,   wpSelectDir,wpSelectComponents,wpSelectProgramGroup,wpSelectTasks,   wpReady wpPreparing,wpInstalling,wpInfoAfter,wpFinished

更改各个代码节并查看结果。 获得可追溯的结果更容易,更快捷。

版本A:

enter image description here

和任务列表结果。

enter image description here

为什么用.ComponentsList来骗人?

  • 您不需要额外的活动。
  • .ComponentsList中选择它,并在.Taskslist中控制它。
  • 如果您未选择任何内容,则.Taskslist不可见。
  • [代码]部分中的所有代码都没有多余的代码。

现在,我们尝试版本B

转到[任务]部分并查找
; Disabled we need it later -----------------------------------------------------

禁用前四行,然后启用后四行。

搜索procedure CurPageChanged(CurPageID: Integer);

在事件WizardForm.TasksList.OnClickCheck := @TaskListClickCheck;上方添加
以及.TasksList的程序。

此处介绍了捕获所选值所需的内容。

如何使用事件WizardForm.TasksList.OnClickCheck和此处的函数自由选择名称procedure TaskListClickCheck(Sender: TObject);或如何处理取决于您要实现的要求。

procedure TaskListClickCheck(Sender: TObject);
begin
    For I := 1 to WizardForm.TasksList.Items.Count -1 do begin
        if WizardForm.TasksList.Checked[I] then 
           WizardForm.TasksList.ItemCaption[I] := Copy(WizardForm.TasksList.ItemCaption[I],1,2) +
           ' <-------- Your choice : Not correct? Please change the selection' else
           WizardForm.TasksList.ItemCaption[I] := Copy(WizardForm.TasksList.ItemCaption[I],1,2);
    end;
end;

procedure InitializeWizard();
begin
  WizardForm.TasksList.OnClickCheck := @TaskListClickCheck;
end;

//procedure CurPageChanged(CurPageID: Integer);

enter image description here

  • 现在我们需要一个事件来拦截选择。
  • 没有额外的代码,选择始终为“ A”。
  • 最后一次进入决赛名单之前,是时候晚了一点吗?
  • 用户认为他快完成了!
  • Name: "main"; Description: "variants"; Types: custom的{​​{1}}等部分现已无用。最好也将其禁用。

您在哪里可以找到所有这些信息?

查看“ Inno设置”帮助。 搜索.ComponentsList
在那里我们可以看到WizardForm.TasksList
(用过的property TasksList: **TNewCheckListBox**; read;是蓝色的)

enter image description here

因此,我们单击 TNewCheckListBox 并获取。

enter image description here

我们可以更轻松地(直接方式:变量的值)。
但是在这里,我不想让它变得过于复杂并且不直接使用它只会造成混乱。


只是在我不理解为代码编写服务的现有脚本中使用现有代码。

仅作为初步帮助来理解它。