8

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')?

thoiz_vd
  • 89
  • 2
  • 4

2 Answers2

12

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;
Robert Love
  • 12,447
  • 2
  • 48
  • 80
  • @Robert - thanks for that. I get a type mismatch error at this line: `Radio := (InputOptionPage as TRadioButton) ;`. Here's the code: `For CompIndex := 0 to InputOptionPage.ComponentCount -1 do begin if (InputOptionPage is TRadioButton) then begin Radio := (InputOptionPage as TRadioButton) ; Radio.OnClick := RadioButtonClick ; end ; end ; ` – rossmcm May 03 '11 at 21:03
  • ...I wish I knew how you can format code properly in comments. Sigh. – rossmcm May 03 '11 at 21:04
  • I see the bug... That's what I get for not compiling/testing the code. Notice the addition of .components[I] – Robert Love May 03 '11 at 21:12
  • `Radio := (InputOptionPage.Components[CompIndex] as TRadioButton) ;` @Robert - same error - type mismatch! – rossmcm May 03 '11 at 21:19
  • I really screwed up, there is an easier way. Updated. – Robert Love May 03 '11 at 23:12
2

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;
Robert Love
  • 12,447
  • 2
  • 48
  • 80