微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我在InnoSetup脚本的“Additional Tasks”页面添加一个复选框
[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 ;

解决方法

任务复选框实际上是 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.',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.',MB_OK)
      else
        MsgBox('First task has NOT been checked.',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;

原文地址:https://www.jb51.cc/delphi/103040.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐