Checkbox 如何在InnoSetup向导页面中读取和设置复选框的值?

Checkbox 如何在InnoSetup向导页面中读取和设置复选框的值?,checkbox,inno-setup,pascalscript,Checkbox,Inno Setup,Pascalscript,我在InnoSetup脚本的“附加任务”页面中添加了一个复选框,其中包含 [Tasks] Name: "StartMenuEntry" ; Description: "Start my app when Windows starts" ; GroupDescription: "Windows Startup"; MinVersion: 4,4; 我想在显示wpSelectTasks页面时初始化此复选框,并在单击Next按钮时读取该值。我无法确定如何访问复选框“checked”值 functi

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

[Tasks]
Name: "StartMenuEntry" ; Description: "Start my app when Windows starts" ; GroupDescription: "Windows Startup"; MinVersion: 4,4; 
我想在显示
wpSelectTasks
页面时初始化此复选框,并在单击
Next
按钮时读取该值。我无法确定如何访问复选框“checked”值

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 ;     
函数NextButtonClick(CurPageID:Integer):布尔;
变量
选择任务页面:TWizardPage;
StartupCheckbox:TCheckbox;
开始
结果:=真;
案例CurPageID
wpSelectTasks:
开始
SelectTasksPage:=PageFromID(wpSelectTasks);

StartupCheckbox:=TCheckbox(SelectTasksPage…{任务复选框实际上是复选框中的项目。如果您知道它们的索引,您可以非常轻松地访问它们。请注意,这些项目可以分组(这只是您的情况),并且每个新组在该复选框中也有一个项目,因此对于您的情况,项目索引将为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;
下面举例说明了当您有两个不同组的任务时,复选框的外观:

要按任务说明访问任务复选框,请尝试以下操作:

[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;   
[设置]
AppName=任务列表
AppVersion=1.0
DefaultDirName={pf}\TasksList
[任务]
名称:“任务”说明:“任务说明”组说明:“组1”;
[守则]
函数NextButtonClick(CurPageID:Integer):布尔值;
变量
索引:整数;
开始
结果:=真;
如果CurPageID=wpSelectTasks,则
开始
索引:=WizardForm.TasksList.Items.IndexOf('TaskDescription');
如果索引为-1,则
开始
如果选中了WizardForm.TasksList
MsgBox('已检查第一个任务',MB信息,MB_OK)
其他的
MsgBox('第一个任务尚未检查',MB信息,MB_OK);
结束;
结束;
结束;
过程CurPageChanged(CurPageID:Integer);
变量
索引:整数;
开始
如果CurPageID=wpSelectTasks,则
开始
索引:=WizardForm.TasksList.Items.IndexOf('TaskDescription');
如果索引为-1,则
WizardForm.TasksList.Checked[Index]:=False;
结束;
结束;

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

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


通常情况下,您不需要这样做。您只需在涉及自动启动的注册表项中包含带有特定任务的“Tasks”参数。感谢@Sertac,是的,我意识到了这一点,但我希望在调用安装程序时从命令行参数初始化复选框的状态,并且我希望能够在izard页面,因此我可以使用它来影响以后脚本的行为。另外,这是我想知道通常如何做的事情…不客气!无论如何,我不喜欢这种索引硬编码,但是我找不到一种方法如何通过任务名获取索引,您可以使用
WizardForm.TasksList.Items.IndexOf('tasksdescription'))
查找复选框索引,但它是按任务描述,而不是按任务名称。同意。我已经做了更改。有一个更好的函数:
IsTaskSelected('tata'))
,使用索引对我不起作用。此外,我建议在
PrepareToInstall
回调中执行操作,并且只在
NextButtonClick
中存储全局变量,当然是因为可能会在back上按下。@v.oddou,你是对的,但是OP知道
IsTaskSelected
函数。此外,还有一个选择任务的要求(参见问题标题)。为了保持一致,最好使用相同的访问权限来读取和写入项目的选择状态(是的,您可以使用
IsTaskSelected
读取状态并使用索引来设置它,但是,您知道,这并不像您使用相同的方法那样平滑).你的第二点我不明白。请注意,这个例子只是为了说明目的。它不是一个真正的脚本。目的只是为了显示读/写访问。@v.oddou,P.s.我总是测试我发布的内容,除非我明确地说我没有。也许你使用了错误的索引,因为例如组也是项目。我不知道。但是当然,如果您只需要读取状态,只需使用
IsTaskSelected
。这个问题是关于读写访问。。。
[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;