inno setup custom page with checkbox and dropdown list

10,071

You might take a script like this as an inspiration:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output

[Files]
Source: "Readme.txt"; Flags: dontcopy

[Code]
var
  Button: TNewButton;
  ComboBox: TNewComboBox;
  CheckBox1: TNewCheckBox;
  CheckBox2: TNewCheckBox;
  CustomPage: TWizardPage;  

procedure ComboBoxChange(Sender: TObject);
begin
  case ComboBox.ItemIndex of
    0:
    begin
      CheckBox1.Checked := True;
      CheckBox2.Checked := False;
    end;
    1:
    begin
      CheckBox1.Checked := False;
      CheckBox2.Checked := True;
    end;
    2:
    begin
      CheckBox1.Checked := True;
      CheckBox2.Checked := True;
    end;
    3:
    begin
      CheckBox1.Checked := False;
      CheckBox2.Checked := False;
    end;
  end;
end;

procedure ButtonClick(Sender: TObject);
var
  ErrorCode: Integer;
begin
  ExtractTemporaryFile('Readme.txt');
  if not ShellExec('', ExpandConstant('{tmp}\Readme.txt'), '', '', 
    SW_SHOW, ewNoWait, ErrorCode)
  then
    MsgBox(SysErrorMessage(ErrorCode), mbError, MB_OK);
end;

procedure InitializeWizard;
var
  DescLabel: TLabel;
begin
  CustomPage := CreateCustomPage(wpSelectDir, 'Caption', 'Description');

  DescLabel := TLabel.Create(WizardForm);
  DescLabel.Parent := CustomPage.Surface;
  DescLabel.Left := 0;
  DescLabel.Top := 0;
  DescLabel.Caption := 'Select an item...';

  ComboBox := TNewComboBox.Create(WizardForm);
  ComboBox.Parent := CustomPage.Surface;
  ComboBox.Left := 0;
  ComboBox.Top := DescLabel.Top + DescLabel.Height + 6;  
  ComboBox.Width := 220;
  ComboBox.Style := csDropDownList;
  ComboBox.Items.Add('Check CheckBox1');
  ComboBox.Items.Add('Check CheckBox2');
  ComboBox.Items.Add('Check CheckBox1 and CheckBox2');
  ComboBox.Items.Add('Uncheck CheckBox1 and CheckBox2');
  ComboBox.OnChange := @ComboBoxChange;

  CheckBox1 := TNewCheckBox.Create(WizardForm);
  CheckBox1.Parent := CustomPage.Surface;
  CheckBox1.Left := 0;
  CheckBox1.Top := ComboBox.Top + ComboBox.Height + 6;
  CheckBox1.Caption := 'CheckBox1';

  CheckBox2 := TNewCheckBox.Create(WizardForm);
  CheckBox2.Parent := CustomPage.Surface;
  CheckBox2.Left := 0;
  CheckBox2.Top := CheckBox1.Top + CheckBox1.Height + 6;
  CheckBox2.Caption := 'CheckBox2';

  Button := TNewButton.Create(WizardForm);
  Button.Parent := CustomPage.Surface;
  Button.Left := 0;
  Button.Top := CheckBox2.Top + CheckBox2.Height + 6;
  Button.Caption := 'Readme';
  Button.OnClick := @ButtonClick;
end;
Share:
10,071
grahamskaraoke
Author by

grahamskaraoke

Updated on June 05, 2022

Comments

  • grahamskaraoke
    grahamskaraoke almost 2 years

    Is it possible to have a custom page with a drop down list, check boxes, and a button possibly changing the check boxes based on what is chosen from the drop down list. The button will just be used to display a readme text file. I am really not familiar with python scripting but have managed to create a drop down list.

  • WASasquatch
    WASasquatch over 9 years
    @TLama Sorry to butt in so late. But is there a way to reference a checked box later? Similar to checking components?
  • TLama
    TLama over 9 years
    @WASasquatch, sorry, but I think I don't understand. I'm accessing check boxes from different methods here. Or, what do you mean by later ?
  • WASasquatch
    WASasquatch over 9 years
    @TLama for example, lets say I am setting a language, and will later write to registry the language Eg "cs_CZ" Is there also a way to make only one box selectable? I'm trying to find reference for all that but it seems I must learn Pascal?
  • TLama
    TLama over 9 years
    @WASasquatch, only one check box selectable ? It sounds more like a task for a group of radio buttons (TNewRadioButton). Besides, Inno Setup reference is here.
  • WASasquatch
    WASasquatch over 9 years
    @TLama it contains no Custom Page dynamics besides the examples.
  • TLama
    TLama over 9 years
    @WASasquatch, the Support Classes Reference describes (also) visual component classes. A good resource for learning Inno Setup basics is Miral's blog. Inno Setup itself uses a Pascal Script based language, which is closest to Delphi, but it's limited in many ways.