Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

inno setup - How do read and set the value of a checkbox in an InnoSetup wizard page?

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; 

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 ;     
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

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

enter image description here

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;   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...