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

后端 未结 2 1460
别那么骄傲
别那么骄傲 2020-12-16 02:54

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

[Tasks]
Name: \"StartMenuEntry\" ; Description: \"Start my app when Wind         


        
相关标签:
2条回答
  • 2020-12-16 03:39

    Great answer above. Gave me just what I needed.

    I had a case where I have a bunch of secondary installers that I used the 'checkonce' option on, but I wanted them to be re-checked if the folder was missing (e.g. the user wiped out the install folder manually), e.g.

    [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;
    
    0 讨论(0)
  • 2020-12-16 03:49

    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;   
    
    0 讨论(0)
提交回复
热议问题