Checkbox :: Select one at a time - inno-setup

This is the code section from inno setup.My intention is to make two Checkbox where at a time one is being selected.
But this code return error when first checkbox is clicked.
[code]
procedure CheckBoxOnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if CheckBox.Checked then ///error:"Could not call proc" [sud it be global if then how to or what to change?]
BEGIN
CheckBox.State := cbUnchecked;
Box2.State := cbChecked;
END else
BEGIN
CheckBox.State := cbChecked;
Box2.State := cbUnchecked;
END;
end;
procedure Box2OnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if Box2.Checked then ///error:same
BEGIN
CheckBox.State := cbChecked;
Box2.State := cbUnchecked;
END else
BEGIN
CheckBox.State := cbUnchecked;
Box2.State := cbChecked;
END;
end;
procedure CreateTheWizardPages;
var
Page: TWizardPage;
Box2,CheckBox: TNewCheckBox;
begin
{ TButton and others }
Page := CreateCustomPage(wpWelcome, '', '');
CheckBox := TNewCheckBox.Create(Page);
CheckBox.Top :=ScaleY(8)+ScaleX(50);
CheckBox.Width := Page.SurfaceWidth;
CheckBox.Height := ScaleY(17);
CheckBox.Caption := 'Do this';
CheckBox.Checked := True;
CheckBox.OnClick := #CheckBoxOnClick;
CheckBox.Parent := Page.Surface;
Box2 := TNewCheckBox.Create(Page);
Box2.Top :=ScaleY(8)+ScaleX(70);
Box2.Width := Page.SurfaceWidth;
Box2.Height := ScaleY(17);
Box2.Caption := 'No,Thanks.';
Box2.Checked := False;
Box2.OnClick := #Box2OnClick;
Box2.Parent := Page.Surface;
end;
procedure InitializeWizard();
//var
begin
{ Custom wizard pages }
CreateTheWizardPages;
end;
Please tell me where to change..

The cause of your error is that your are referencing CheckBox which is defined locally in that method. At this point CheckBox has not been created. Which means your calling CheckBox.Checked when CheckBox is undefined (most likely NIL)
Each declaration of CheckBox represents a new variable and does not reference the other variables with the same name. This is due to scoping rules.
One option to solve your problem is to remove the local declarations of Box2, and CheckBox in each method and declare them globally.

Related

Run Files and Programs according to custom checkboxes after clicking on Finish Button in Inno Setup

I have created some custom checkboxes in the finished page of Inno Setup.
For example launching an app, opening a text file etc.
I need when the user clicks on the finish button I check those checkboxes and do whatever that is needed. How can I do such a thing in Inno Setup?
Here is the code:
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpFinished then
begin
Launch := TNewCheckBox.Create(WizardForm);
Launch.Parent := WizardForm;
Launch.Left := WizardForm.ClientWidth - 350;
Launch.Top := WizardForm.CancelButton.Top;
Launch.Width := 120;
Launch.Height := WizardForm.CancelButton.Height;
Launch.Caption := 'Launch';
end;
end;
In NextButtonClick event handler, test if your checkbox is checked and act accordingly.
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
Path: string;
Message: string;
begin
if CurPageID = wpFinished then
begin
if Launch.Checked then
begin
Path := ExpandConstant('{app}\MyProg.exe');
if ExecAsOriginalUser(Path, '', '', SW_SHOW, ewNoWait, ResultCode) then
begin
Log('Executed MyProg');
end
else
begin
Message := 'Error executing MyProg: ' + SysErrorMessage(ResultCode);
MsgBox(Message, mbError, MB_OK);
end;
end;
end;
Result := True;
end;
Simply check the checkbox state:
if (Launch.Checked = True) then
begin
// checkbox is checked
end
else
begin
// Checkbox is unchecked
end;
The best place is to use function NextButtonClick(CurPageID: Integer): Boolean;
however in that case you need to make your checkbox a global variable (so it is accessible).

Inno Setup remove/hide/disable the NextButton on a custom wizard page

I would like to disable the "Next" button from my custom wizard page.
The fact is that I've no issue to change the caption of it for example, but if I set the NextButton.Enabled to False, Inno Setup show me the Welcome page instead of my Custom Page. Any Idea?
procedure CurPageChanged(CurPageID: Integer);
begin
WizardForm.NextButton.Caption := 'test'; { Works }
WizardForm.NextButton.Enabled := false ; { delete my custom page }
WizardForm.CancelButton.Caption := 'Finish';
end;
procedure CreateTheWizardPages;
var
Page: TWizardPage;
TestConnectivityButton: TButton;
begin
Page := CreateCustomPage(wpWelcome, 'Connectivity Test', '');
CurPageChanged(Page.ID);
TestConnectivityButton := TButton.Create(Page);
TestConnectivityButton.Width := ScaleX(100);
TestConnectivityButton.Height := ScaleY(30);
TestConnectivityButton.Caption := CustomMessage('TestConnectivityAccessButtonLabel');
TestConnectivityButton.OnClick := #TestConnectivityWindow;
TestConnectivityButton.Parent := Page.Surface;
end;
procedure InitializeWizard;
begin
CreateTheWizardPages;
end;
You have to make the changes, when you enter your custom page only – When CurPageChanged event function is called with CurPageID equal to Page.ID.
And you cannot call CurPageChanged yourself!
var
Page: TWizardPage;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = Page.ID then
begin
WizardForm.NextButton.Caption := 'Test';
WizardForm.NextButton.Enabled := False ;
WizardForm.CancelButton.Caption := 'Finish';
end;
end;
procedure CreateTheWizardPages;
var
TestConnectivityButton: TButton;
begin
Page := CreateCustomPage(wpWelcome, 'Connectivity Test', '');
TestConnectivityButton := TButton.Create(Page);
TestConnectivityButton.Width := ScaleX(100);
TestConnectivityButton.Height := ScaleY(30);
TestConnectivityButton.Caption :=
CustomMessage('TestConnectivityAccessButtonLabel');
TestConnectivityButton.OnClick := #TestConnectivityWindow;
TestConnectivityButton.Parent := Page.Surface;
end;
Another option is using Page.OnActivate event instead of CurPageChanged event function.

How to disable NextButton when file is not selected on InputFilePage (CreateInputFilePage)?

My Inno Setup program have a custom "input file page" that was created using CreateInputFilePage.
How can I disable the NextButton in this page until the file path is properly picked by the user?
In other words, I need to make the NextButton unclickable while the file selection form is empty, and clickable when the file selection form is filled.
Thank you.
The easiest way is to use NextButtonClick to validate the inputs and display an error message when the validation fails.
var
FilePage: TInputFileWizardPage;
procedure InitializeWizard();
begin
FilePage := CreateInputFilePage(wpSelectDir, 'caption', 'description', 'sub caption');
FilePage.Add('prompt', '*.*', '.dat');
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if (CurPageID = FilePage.ID) and
(Length(FilePage.Edits[0].Text) = 0) then
begin
MsgBox('Please select a file.', mbError, MB_OK);
WizardForm.ActiveControl := FilePage.Edits[0];
Result := False;
end;
end;
If you really want to update the "Next" button state while the input changes, it is a bit more complicated:
procedure FilePageEditChange(Sender: TObject);
begin
WizardForm.NextButton.Enabled := (Length(TEdit(Sender).Text) > 0);
end;
procedure FilePageActivate(Sender: TWizardPage);
begin
FilePageEditChange(TInputFileWizardPage(Sender).Edits[0]);
end;
procedure InitializeWizard();
var
Page: TInputFileWizardPage;
Edit: TEdit;
begin
Page := CreateInputFilePage(wpSelectDir, 'caption', 'description', 'sub caption');
{ To update the Next button state when the page is entered }
Page.OnActivate := #FilePageActivate;
Edit := Page.Edits[Page.Add('prompt', '*.*', '.dat')];
{ To update the Next button state when the edit contents changes }
Edit.OnChange := #FilePageEditChange;
end;

How to hide the main panel and show an image over the whole page?

I have created a custom welcome page with an image on it but the main panel on the top remains to be displayed. For what I want to achieve see image below:
Here is the code:
[Code]
procedure InitializeWizard;
var
BitmapFileName: string;
BitmapImage: TBitmapImage;
WelcomePage: TWizardPage;
begin
WelcomePage := CreateCustomPage(wpWelcome, '', '');
BitmapFileName := ExpandConstant('{tmp}\DataNova_Logo.bmp');
ExtractTemporaryFile(ExtractFileName(BitmapFileName));
BitmapImage := TBitmapImage.Create(WelcomePage);
BitmapImage.AutoSize := True;
BitmapImage.Bitmap.LoadFromFile(BitmapFileName);
BitmapImage.Cursor := crHand;
BitmapImage.Left := 10;
BitmapImage.Top := 10;
BitmapImage.Parent := WelcomePage.Surface;
end;
How to show the image over the whole page with the main panel hidden ?
You need to hide the Bevel1, MainPanel and the InnerNotebook components when you switch to your welcome page and show them again when you leave it. As the opposite, the image you need to show only when you're showing your welcome page since it covers the whole page area. So the following code will do the trick:
[Code]
var
WelcomePageID: Integer;
BitmapImage: TBitmapImage;
procedure InitializeWizard;
var
WelcomePage: TWizardPage;
begin
WelcomePage := CreateCustomPage(wpWelcome, '', '');
WelcomePageID := WelcomePage.ID;
BitmapImage := TBitmapImage.Create(WizardForm);
BitmapImage.Bitmap.LoadFromFile('C:\Image.bmp');
BitmapImage.Top := 0;
BitmapImage.Left := 0;
BitmapImage.AutoSize := True;
BitmapImage.Cursor := crHand;
BitmapImage.Visible := False;
BitmapImage.Parent := WizardForm.InnerPage;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
BitmapImage.Visible := CurPageID = WelcomePageID;
WizardForm.Bevel1.Visible := CurPageID <> WelcomePageID;
WizardForm.MainPanel.Visible := CurPageID <> WelcomePageID;
WizardForm.InnerNotebook.Visible := CurPageID <> WelcomePageID;
end;

Add a custom input field to Inno Setup

I am making use of Inno Setup (it's amazing!). I was hoping to customise the installer so that I can accept a string from the user in the form of an input field and maybe add a message to it.
How can I do this? I had a look through the docs, google search and not much came up!
Thanks all for any help
You can use Pascal scripting in InnoSetup to create new pages for the installer. These pages can be integrated into the normal installation flow. This is well documented within the InnoSetup documentation (Google search should also come up with samples). Also the Samples folder within your Program Files\InnoSetup has some code examples.
Some time ago, there was a software called InnoSetup Form designer, which allowed you to visually design the page. The link is still there, but on the page I could not find the download. Maybe if you look around a bit you can find it?
EDIT
This is a sample for a page I made once. This is the code section of the ISS file.[Code]
var
EnableFolderPage: Boolean;
lblBlobFileFolder: TLabel;
lblBlobFileWarning1: TLabel;
lblBlobFileWarning2: TLabel;
tbBlobFileFolder: TEdit;
btnBlobFileFolder: TButton;
function GetBlobFolder(param: String): String;
begin
Result := Trim(tbBlobFileFolder.Text);
end;
{ BlobFileForm_Activate }
procedure BlobFileForm_Activate(Page: TWizardPage);
var
s: string;
begin
s := Trim(tbBlobFileFolder.Text);
if (s = '') then
begin
tbBlobFileFolder.Text := ExpandConstant('{sys}');
end;
end;
{ BlobFileForm_NextButtonClick }
function BlobFileForm_NextButtonClick(Page: TWizardPage): Boolean;
var
s: string;
begin
s := Trim(tbBlobFileFolder.Text);
if (s = '') then
begin
MsgBox(ExpandConstant('{cm:BlobFileForm_NoFolder}'), mbError, MB_OK);
Result := false;
end else
begin
if not DirExists(s) then
begin
MsgBox(ExpandConstant('{cm:BlobFileForm_DirDoesntExist}'), mbError, MB_OK);
Result := false;
end else
begin
Result := True;
end;
end;
end;
procedure btnBlobFileFolder_Click(sender: TObject);
var
directory: string;
begin
if BrowseForFolder('', directory, true) then
begin
tbBlobFileFolder.Text := directory;
end;
end;
{ BlobFileForm_CreatePage }
function BlobFileForm_CreatePage(PreviousPageId: Integer): Integer;
var
Page: TWizardPage;
begin
Page := CreateCustomPage(
PreviousPageId,
ExpandConstant('{cm:BlobFileForm_Caption}'),
ExpandConstant('{cm:BlobFileForm_Description}')
);
{ lblBlobFileFolder }
lblBlobFileFolder := TLabel.Create(Page);
with lblBlobFileFolder do
begin
Parent := Page.Surface;
Caption := ExpandConstant('{cm:BlobFileForm_lblBlobFileFolder_Caption0}');
Left := ScaleX(8);
Top := ScaleY(8);
Width := ScaleX(167);
Height := ScaleY(13);
end;
{ lblBlobFileWarning1 }
lblBlobFileWarning1 := TLabel.Create(Page);
with lblBlobFileWarning1 do
begin
Parent := Page.Surface;
Caption := ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning1_Caption0}');
Left := ScaleX(8);
Top := ScaleY(80);
Width := ScaleX(50);
Height := ScaleY(13);
Font.Color := -16777208;
Font.Height := ScaleY(-11);
Font.Name := 'Tahoma';
Font.Style := [fsBold];
end;
{ lblBlobFileWarning2 }
lblBlobFileWarning2 := TLabel.Create(Page);
with lblBlobFileWarning2 do
begin
Parent := Page.Surface;
Caption :=
ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption0}') + #13 +
ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption1}') + #13 +
ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption2}') + #13 +
ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption3}') + #13 +
ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption4}');
Left := ScaleX(8);
Top := ScaleY(96);
Width := ScaleX(399);
Height := ScaleY(133);
AutoSize := False;
WordWrap := True;
end;
{ tbBlobFileFolder }
tbBlobFileFolder := TEdit.Create(Page);
with tbBlobFileFolder do
begin
Parent := Page.Surface;
Left := ScaleX(8);
Top := ScaleY(24);
Width := ScaleX(401);
Height := ScaleY(21);
TabOrder := 0;
end;
{ btnBlobFileFolder }
btnBlobFileFolder := TButton.Create(Page);
with btnBlobFileFolder do
begin
Parent := Page.Surface;
Caption := ExpandConstant('{cm:BlobFileForm_btnBlobFileFolder_Caption0}');
Left := ScaleX(320);
Top := ScaleY(48);
Width := ScaleX(91);
Height := ScaleY(23);
TabOrder := 1;
end;
with Page do
begin
OnActivate := #BlobFileForm_Activate;
OnNextButtonClick := #BlobFileForm_NextButtonClick;
end;
with btnBlobFileFolder do
begin
OnClick := #btnBlobFileFolder_Click;
end;
Result := Page.ID;
end;
procedure InitializeWizard();
begin
BlobFileForm_CreatePage(wpSelectDir);
end;
EDIT 2
To write the value the user entered to a registry key, create a new function:
function GetUserEnteredText(param: String): String;
begin
Result := Trim(tbTextBox.Text);
end;
This function simply returns what was entered in the text box. Please note that the function must take a string parameter - even though you ignore it!
In the [Registry] section of your script, declare the key that should be written like that:
Root: HKLM; Subkey: SOFTWARE\MyCompany\MyTool; ValueType: string; ValueName: MyValue; ValueData: {code:GetUserEnteredText}; Flags: createvalueifdoesntexist uninsdeletekeyifempty uninsdeletevalue
This creates a registry value named "MyValue" in HKLM\SOFTWARE\MyCompany\MyTool that contains what the user entered in the text box.
Here is shorter code to add a custom page to Inno Setup installer with an Input Field:
var
CustomQueryPage: TInputQueryWizardPage;
procedure AddCustomQueryPage();
begin
CustomQueryPage := CreateInputQueryPage(
wpWelcome,
'Custom message',
'Custom description',
'Custom instructions');
{ Add items (False means it's not a password edit) }
CustomQueryPage.Add('Custom Field:', False);
end;
procedure InitializeWizard();
begin
AddCustomQueryPage();
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
{ Read custom value }
MsgBox('Custom Value = ' + CustomQueryPage.Values[0], mbInformation, MB_OK);
end;
end;

Resources