Hook standard Inno Setup checkbox

2019-04-07 15:19发布

I added an InputOptionWizardPage for selecting tasks. This works fine, but I would like to add some custom functionality. One task is dependent on the other, so if the second checkbox is checked, the first should be checked and grayed out.

To do this, I need to access the properties of a checkbox. I found ways to do this using a completely custom page, where I would explicitly create the checkbox myself, but that would be a lot of work, since most of what I have so far is satisfactory.

How can I hook a checkbox that was created by Inno Setup, using MyInputOptionWizardPage.Add('This will add a checkbox with this caption')?

标签: inno-setup
2条回答
别忘想泡老子
2楼-- · 2019-04-07 15:49

You can also control tasks by parent relationships, it gives you a similar behavior to what your asking for but is not 100% the same. I know this does not answer your question directly, but intends to give you an option that maybe easier to implement. Doing it this way you don't have to worry about managing a custom dialog at all.

[Setup]
;This allows you to show Lines showing parent / Child Relationships
ShowTasksTreeLines=yes

[Tasks]
;Parent Tasks don't use "\"
Name: p1; Description: P1 Test; 
;Child Tasks are named ParentTaskName\ChildTaskName
;Flag don't inheritcheck:Specifies that the task 
;should not automatically become checked when its parent is checked 
Name: p1\c1; Description: C1 Test; Flags: dontinheritcheck;
Name: p1\c2; Description: C2 Test; 
;Default behavior is that child must be selected 
;when a parent is selected
;this can be overridden using the:
;doninheritcheck flag and the checkablealone flag.
Name: p2; Description: P2 Test; Flags: checkablealone;
Name: p2\c1; Description: P2-C1 Test; Flags: dontinheritcheck;
Name: p2\c2; Description: P2-C2 Test; Flags: dontinheritcheck;
查看更多
该账号已被封号
3楼-- · 2019-04-07 16:06

In attempt to answer your question directly.

I suspect you have used CreateInputOptionPage() which returns a TInputOptionWizardPage

This has the '.Add('Example')` method that you mention.

TInputOptionWizard descends TWizardPage which descends from TComponent which has the methods you need.

Update: Replaced original Code, this example is based on a review of options available in the InnoSetup source code of ScriptClasses_C.pas My original example I thought that TRadioButton and TCheckBox where individual controls. They instead its one control called TNewCheckListBox. There is a couple of ways someone could pull this off but the safest way is to use.

This example is a complete Inno Setup Script.

[Setup]
AppName='Test Date Script'
AppVerName='Test Date Script'
DefaultDirName={pf}\test
[Code]

const
 cCheckBox = false;
 cRadioButton  = true;


var
  Opt : TInputOptionWizardPage; 

function BoolToStr(Value : Boolean) : String; 
begin
  if Value then
    result := 'true'
  else
    result := 'false';
end;

procedure ClickEvent(Sender : TObject);
var
 Msg : String;
 I   : Integer;
begin
   // Click Event, allowing inspection of the Values.
    Msg := 'The Following Items are Checked' +#10#13; 
    Msg := Msg + 'Values[0]=' + BoolToStr(Opt.Values[0]) +#10#13;
    Msg := Msg + 'Values[1]=' + BoolToStr(Opt.Values[1]) +#10#13;
    Msg := Msg + 'Values[2]=' + BoolToStr(Opt.Values[2]);

    MsgBox(Msg,mbInformation,MB_OK);
end;
procedure InitializeWizard();
var
  I : Integer; 
  ControlType : Boolean;
begin
  ControlType := cCheckBox;
  Opt := CreateInputOptionPage(1,'Caption','Desc','SubCaption',ControlType, false);
  Opt.Add('Test1');
  Opt.Add('Test2');
  Opt.Add('Test3');

  // Assign the Click Event.
  Opt.CheckListBox.OnClickCheck := @ClickEvent;  
end;
查看更多
登录 后发表回答