How can I add a check box for optional files during install in Inno Setup?

You don't have to manually create checkboxes for that. The standard way to let the user choose what to install is to use the [Types] and [Components] sections of your script file.

Take a look at the Components.iss script located in your Inno Setup install folder\examples.

; -- Components.iss --
; Demonstrates a components-based installation.

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING .ISS SCRIPT FILES!

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Types]
Name: "full"; Description: "Full installation"
Name: "compact"; Description: "Compact installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom

[Components]
Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed
Name: "help"; Description: "Help File"; Types: full
Name: "readme"; Description: "Readme File"; Types: full
Name: "readme\en"; Description: "English"; Flags: exclusive
Name: "readme\de"; Description: "German"; Flags: exclusive

[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Components: program
Source: "MyProg.chm"; DestDir: "{app}"; Components: help
Source: "Readme.txt"; DestDir: "{app}"; Components: readme\en; Flags: isreadme
Source: "Readme-German.txt"; DestName: "Liesmich.txt"; DestDir: "{app}"; Components: readme\de; Flags: isreadme

[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"

At runtime, the installer presents this dialog within the wizard:

Components dialog


// Create:
for i := 0 to g_SetupX_Count do begin
    WizardForm.ComponentsList.AddCheckBox(g_SetupX_Name[i], '', 0, g_SetupX_Active[i], true, false, false, nil);
    g_SetupX_CompListIndex[i] := nextPosi;
    nextPosi := nextPosi + 1;
end;

// Evaluate:
for i := 0 to g_SetupX_Count do begin
    g_SetupX_Active[i] := WizardForm.ComponentsList.Checked[g_SetupX_CompListIndex[i]];
end;

You need to make a Check function which will return state of the check box from the [Code] section of your script. Something like this might do what you want, but before the code script I would correct you in the following:

  • use TNew... classes where you're able to, so in your case use TNewEdit instead of TEdit
  • use TWizardPage.Surface as a Parent if you want to have a certain component on the page (here I'm not sure if that's your intention, just pointing this out :-)
  • format your code, it doesn't need to be so flat

In the following example I've used Check function called InstallHelpFile for conditional install of a certain file, in this case MyProg.chm. The Check function works simply; when you return True to the function, the file is processed, skipped is when you return False.

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

[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"; Check: InstallHelpFile;
[Code]
var
  InstallHelpCheckBox: TNewCheckBox;  

procedure InitializeWizard;
var  
  LabelFolder: TLabel;  
  MainPage: TWizardPage;  
  FolderToInstall: TNewEdit;  
begin
  MainPage := CreateCustomPage(wpWelcome, '', '');
  LabelFolder := TLabel.Create(MainPage);
  LabelFolder.Parent := WizardForm;
  LabelFolder.Top := 164;
  LabelFolder.Left := 6;
  LabelFolder.Caption := 'Directory:'

  FolderToInstall := TNewEdit.Create(MainPage);
  FolderToInstall.Parent := MainPage.Surface;
  FolderToInstall.Top := 182;
  FolderToInstall.Left := 85;
  FolderToInstall.Width := 380;
  FolderToInstall.Text :=  WizardDirValue;
  FolderToInstall.ReadOnly := True;

  InstallHelpCheckBox := TNewCheckBox.Create(MainPage);
  InstallHelpCheckBox.Parent := MainPage.Surface;
  InstallHelpCheckBox.Top := FolderToInstall.Top + FolderToInstall.Height + 8;
  InstallHelpCheckBox.Left := FolderToInstall.Left;
  InstallHelpCheckBox.Width := FolderToInstall.Width;
  InstallHelpCheckBox.Caption := 'Install help file';
end;

function InstallHelpFile: Boolean;
begin
  { here is the Check function used above; if you return True to this }
  { function, the file will be installed, when False, the file won't }
  { be installed }
  Result := InstallHelpCheckBox.Checked;
end;

You can do it much easier with CreateInputOptionPage(). See detailed information in Inno Setup help. http://www.jrsoftware.org/ishelp/index.php?topic=scriptpages