如何在 InnoSetup 向导页面中读取和设置复选框的值? [英] How do read and set the value of a checkbox in an InnoSetup wizard page?

查看:13
本文介绍了如何在 InnoSetup 向导页面中读取和设置复选框的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have added a checkbox to the "Additional Tasks" page of an InnoSetup script with

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

我想在 wpSelectTasks 页面显示时初始化这个复选框,并在点击 Next 按钮时读取值.我不知道如何访问复选框已检查"值.

I want to initialize this checkbox when the wpSelectTasks page shows, and read the value when the Next button is clicked. I can't work out how to access the checkbox `checked' value.

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 ;     

推荐答案

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

The task check boxes are in fact items in the WizardForm.TasksList check list box. If you know their indexes you can access them pretty easily. Note, that the items can be grouped (what is just your case) and each new group takes also one item in that check list box, so for your case the item index will be 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 当您有两个不同组的任务时,复选框看起来像这样:

Here is illustrated how the WizardForm.TasksList check list box would looks like when you'd have two tasks with different groups:

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

To access the task check box by its description try the following:

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

这篇关于如何在 InnoSetup 向导页面中读取和设置复选框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆