10

我在 InnoSetup 脚本的“附加任务”页面中添加了一个复选框

[Tasks]
Name: "StartMenuEntry" ; Description: "Start my app when Windows starts" ; GroupDescription: "Windows Startup"; MinVersion: 4,4; 

我想在页面显示时初始化此复选框,并在单击按钮wpSelectTasks时读取值。Next我不知道如何访问复选框“选中”值。

function NextButtonClick(CurPageID: Integer): Boolean;

var
  SelectTasksPage : TWizardPage ;
  StartupCheckbox : TCheckbox ;

begin
Result := true ;
case CurPageID of

    wpSelectTasks :
        begin
        SelectTasksPage := PageFromID (wpSelectTasks) ;
        StartupCheckbox := TCheckbox (SelectTasksPage... { <== what goes here??? }
        StartupCheckboxState := StartupCheckbox.Checked ;
        end ;
    end ;    
end ;     
4

2 回答 2

18

任务复选框实际上是WizardForm.TasksList复选框中的项目。如果你知道它们的索引,你可以很容易地访问它们。请注意,可以对项目进行分组(这只是您的情况),并且每个新组还在该复选框中包含一个项目,因此对于您的情况,项目索引将为 1:

[Setup]
AppName=TasksList
AppVersion=1.0
DefaultDirName={pf}\TasksList

[Tasks]
Name: "TaskEntry"; Description: "Description"; GroupDescription: "Group";

[code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;
  if CurPageID = wpSelectTasks then
  begin
    if WizardForm.TasksList.Checked[1] then
      MsgBox('First task has been checked.', mbInformation, MB_OK)
    else
      MsgBox('First task has NOT been checked.', mbInformation, MB_OK);
  end;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpSelectTasks then
    WizardForm.TasksList.Checked[1] := False;
end;

下图说明了WizardForm.TasksList当您有两个具有不同组的任务时,检查列表框的外观:

在此处输入图像描述

要通过描述访问任务复选框,请尝试以下操作:

[Setup]
AppName=Task List
AppVersion=1.0
DefaultDirName={pf}\TasksList

[Tasks]
Name: "Task"; Description: "Task Description"; GroupDescription: "Group 1";

[code]
function NextButtonClick(CurPageID: Integer): Boolean;
var
  Index: Integer;
begin
  Result := True;
  if CurPageID = wpSelectTasks then
  begin
    Index := WizardForm.TasksList.Items.IndexOf('Task Description');
    if Index <> -1 then
    begin
      if WizardForm.TasksList.Checked[Index] then
        MsgBox('First task has been checked.', mbInformation, MB_OK)
      else
        MsgBox('First task has NOT been checked.', mbInformation, MB_OK);
    end;
  end;
end;

procedure CurPageChanged(CurPageID: Integer);
var
  Index: Integer;
begin
  if CurPageID = wpSelectTasks then
  begin
    Index := WizardForm.TasksList.Items.IndexOf('Task Description');
    if Index <> -1 then    
      WizardForm.TasksList.Checked[Index] := False;
  end;
end;   
于 2012-05-07T23:09:56.330 回答
1

上面的答案很好。给了我我需要的东西。

我有一个案例,我有一堆辅助安装程序,我使用了“checkonce”选项,但如果文件夹丢失,我希望重新检查它们(例如,用户手动清除了安装文件夹),例如

[Tasks]
Name: "InstallPython" ; Description: "Install Python"     ; Flags: checkedonce
Name: "InstallNPP"    ; Description: "Install Notepad++"  ; Flags: checkedonce

[Code]
procedure CurPageChanged(CurPageID: Integer);
var
ItemIx: Integer;

begin
    if CurPageID = wpSelectTasks then begin
        if not DirExists(ExpandConstant('{app}')) then begin
            for ItemIx := 0 to (WizardForm.TasksList.Items.Count - 1) do
                WizardForm.TasksList.Checked[ItemIx] := True;
        end
    end
end;
于 2014-03-03T19:13:51.770 回答