How to change buttons on a custom page in Inno? - inno-setup

My Inno setup installer consist only on 2 custom pages.
in the first custom page show show "Abort" button and "Agree and Install" button
in the second custom page I want to replace the "Abort" button with "Decline" button,
just to change the caption of the button !
I dont know how to adress the page ID of the first and the second page so i cant make it happen.
I have seen how to create custom pages and add them to the wizard in the InitializeWizard procedure.
My problem is that when I create a custom page the default page for install location selection does not appear any more.
What options do I have to keep the default page(install location selection) and also add a my new custom page?
Code:
--------- here are my pages - -----------
procedure CreateTheWizardPages;
var
Page: TWizardPage;
Title: TNewStaticText;
Desc: TRichEditViewer;
CB_border: TPanel;
HPCB: TCheckBox;
HP_Lable:TRichEditViewer;
DSCB: TCheckBox;
DS_Lable:TRichEditViewer;
Footer: TRichEditViewer;
LinkTerms, LinkPP: TNewStaticText;
DeclineButton: TNewButton;
checkx: integer;
begin
Page := CreateCustomPage(
wpWelcome,
ExpandConstant('{cm:MainOfferPageCaption}'),
ExpandConstant('{cm:MainOfferPageDescription}'));
Page.Surface.Notebook.SetBounds(10, 70, ScaleX(WizardForm.Width), ScaleY(500));
{ Title }
Title := TNewStaticText.Create(Page);
Title.Parent := Page.Surface;
Title.Left := ScaleX(0);
Title.Top := ScaleY(0);
Title.Width := ScaleX(200);
Title.Height := ScaleY(30);
Title.Color := -16777186;
Title.Font.Name := 'Verdana';
Title.Font.Style := [fsBold];
Title.Caption := 'Wise Convert app';
Title.Font.size := 12;
Title.TabOrder := 1;
Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TComboBox and others');
{ Title }
Title := TNewStaticText.Create(Page);
Title.Parent := Page.Surface;
Title.Left := ScaleX(0);
Title.Top := ScaleY(0);
Title.Width := ScaleX(200);
Title.Height := ScaleY(30);
Title.Color := -16777186;
Title.Font.Name := 'Verdana';
Title.Font.Style := [fsBold];
Title.Caption := 'Wise Convert app';
Title.Font.size := 18;
Title.TabOrder := 1;
end;
------- here i change the buttons caption ----------
procedure CreateAgreeButton(ParentForm: TSetupForm; nextButton: TNewButton);
var
AgreeButton: TNewButton;
begin
WizardForm.NextButton.Caption := '&Agree and Install';
end;
procedure CreateCancelButton(ParentForm: TSetupForm; CancelButton: TNewButton);
begin
WizardForm.CancelButton.Caption := '&Abort';
WizardForm.backButton.Visible := false;
end;

Related

How to skip custom page based on setup type in Inno Setup

I'm building my setup with server and client installation/setup types.
I need to skip or hide a custom page if user choose server type.
Server type only have a custom page to select SQL instance and a button to launch sqlcmd to install DB, while client installation only copy some files to program directory.
This is my test code with custom page:
[Types]
Name: "Server"; Description: "Server"
Name: "Client"; Description: "Client"
[Components]
Name: "Dictation"; Description: "Dictation"; Types: Client
Name: "DigitalSign"; Description: "Digital Sign"; Types: Client
[Tasks]
Name: "Voisis"; Description: "Voisis"; Components: Dictation
Name: "Recomed"; Description: "Recomed"; Components: Dictation
[Code]
var
Page: TWizardPage;
Panel: TPanel;
Edit0,Edit1,Edit2,Edit3: TNewEdit;
StaticText0, StaticText1,StaticText2,StaticText3: TNewStaticText;
procedure InitializeWizard;
begin
{ Create the pages }
Page := CreateCustomPage (wpInfoBefore, 'Personal Information', 'Who are you?');
Edit0 := TNewEdit.Create(Page);
Edit0.Top := ScaleY(16);
Edit0.Width := Page.SurfaceWidth div 3 - ScaleX(8);
Edit0.Text := 'localhost\WISE';
Edit0.Parent := Page.Surface;
Edit1 := TNewEdit.Create(Page);
Edit1.Top := ScaleY(64);
Edit1.Width := Page.SurfaceWidth div 3 - ScaleX(8);
Edit1.Text := 'sa';
Edit1.Parent := Page.Surface;
Edit2 := TNewEdit.Create(Page);
Edit2.Top := ScaleY(112);
Edit2.Width := Page.SurfaceWidth div 3 - ScaleX(8);
Edit2.Text := 'Password';
Edit2.Parent := Page.Surface;
Edit3 := TNewEdit.Create(Page);
Edit3.Top := ScaleY(160);
Edit3.Width := Page.SurfaceWidth div 3 - ScaleX(8);
Edit3.Text := 'TNewEdit';
Edit3.Parent := Page.Surface;
StaticText0 := TNewStaticText.Create(Page);
Statictext0.Top := ScaleY(2);
StaticText0.Caption := 'Istanza';
StaticText0.AutoSize := True;
StaticText0.Parent := Page.Surface;
StaticText1 := TNewStaticText.Create(Page);
Statictext1.Top := ScaleY(50);
StaticText1.Caption := 'User';
StaticText1.AutoSize := True;
StaticText1.Parent := Page.Surface;
StaticText2 := TNewStaticText.Create(Page);
Statictext2.Top := ScaleY(98);
StaticText2.Caption := 'Password';
StaticText2.AutoSize := True;
StaticText2.Parent := Page.Surface;
StaticText3 := TNewStaticText.Create(Page);
Statictext3.Top := ScaleY(146);
StaticText3.Caption := 'bho';
StaticText3.AutoSize := True;
StaticText3.Parent := Page.Surface;
end;
function ShouldSkipPage(PageID: Integer): Boolean;
begin
Result := False;
if PageID = PageID then
Result := not IsComponentSelected('Server');
end;
In ShouldSkipPage event function, compare the PageID against the TWizardPage.ID of the custom page. And use WizardSetupType support function to test the selected setup type.
var
Page: TWizardPage;
function ShouldSkipPage(PageID: Integer): Boolean;
begin
Result := False;
if Page.ID = PageID then
Result := (WizardSetupType(False) <> 'server');
end;
And obviously, your custom page must show after the "Select Components" page, not before:
Page := CreateCustomPage(wpSelectComponents, ...);
Alternatively, you can handle TWizardPage.OnShouldSkipPage of the custom page.
For an example, see Skip Inno Setup custom page, unless specific radio button is selected on previous page.

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 make work the new added checkboxes with the tasks?

I have added new checkboxes to my inno setup tasks page but i dont know how to make them work with the tasks, i want them to work with the [Tasks] zone in the script.
[Tasks]
Name: "Newcheckboox1"; Description: "Newcheckbox1"; MinVersion: 0.0,5.0
Name: "Newcheckboox2"; Description: "Newcheckbox2"; MinVersion: 0.0,5.0
other tasks checkboxes here.........
Here an image:
Here the code generated when the checkboxes are added:
[Code]
{ RedesignWizardFormBegin } // Don't remove this line!
// Don't modify this section. It is generated automatically.
var
NewGroupBox1: TNewGroupBox;
NewCheckBox1: TNewCheckBox;
NewCheckBox2: TNewCheckBox;
NewCheckBox3: TNewCheckBox;
NewGroupBox2: TNewGroupBox;
NewCheckBox4: TNewCheckBox;
NewCheckBox5: TNewCheckBox;
NewGroupBox3: TNewGroupBox;
NewCheckBox6: TNewCheckBox;
NewCheckBox7: TNewCheckBox;
NewCheckBox8: TNewCheckBox;
procedure RedesignWizardForm;
begin
with WizardForm.SelectTasksLabel do
begin
Visible := False;
Left := ScaleX(392);
end;
{ NewGroupBox1 }
NewGroupBox1 := TNewGroupBox.Create(WizardForm);
with NewGroupBox1 do
begin
Parent := WizardForm.SelectTasksPage;
Left := ScaleX(0);
Top := ScaleY(0);
Width := ScaleX(145);
Height := ScaleY(238);
Caption := 'NewGroupBox1';
end;
{ NewCheckBox1 }
NewCheckBox1 := TNewCheckBox.Create(WizardForm);
with NewCheckBox1 do
begin
Parent := NewGroupBox1;
Left := ScaleX(8);
Top := ScaleY(16);
Width := ScaleX(97);
Height := ScaleY(17);
Caption := 'NewCheckBox1';
end;
{ NewCheckBox2 }
NewCheckBox2 := TNewCheckBox.Create(WizardForm);
with NewCheckBox2 do
begin
Parent := NewGroupBox1;
Left := ScaleX(8);
Top := ScaleY(40);
Width := ScaleX(97);
Height := ScaleY(17);
Caption := 'NewCheckBox2';
end;
{ NewCheckBox3 }
NewCheckBox3 := TNewCheckBox.Create(WizardForm);
with NewCheckBox3 do
begin
Parent := NewGroupBox1;
Left := ScaleX(8);
Top := ScaleY(64);
Width := ScaleX(97);
Height := ScaleY(17);
Caption := 'NewCheckBox3';
end;
NewCheckBox1.TabOrder := 0;
NewCheckBox2.TabOrder := 1;
NewCheckBox3.TabOrder := 2;
{ NewGroupBox2 }
NewGroupBox2 := TNewGroupBox.Create(WizardForm);
with NewGroupBox2 do
begin
Parent := WizardForm.SelectTasksPage;
Left := ScaleX(152);
Top := ScaleY(0);
Width := ScaleX(265);
Height := ScaleY(97);
Caption := 'NewGroupBox2';
end;
{ NewCheckBox4 }
NewCheckBox4 := TNewCheckBox.Create(WizardForm);
with NewCheckBox4 do
begin
Parent := NewGroupBox2;
Left := ScaleX(8);
Top := ScaleY(16);
Width := ScaleX(97);
Height := ScaleY(17);
Caption := 'NewCheckBox4';
end;
{ NewCheckBox5 }
NewCheckBox5 := TNewCheckBox.Create(WizardForm);
with NewCheckBox5 do
begin
Parent := NewGroupBox2;
Left := ScaleX(8);
Top := ScaleY(40);
Width := ScaleX(97);
Height := ScaleY(17);
Caption := 'NewCheckBox5';
end;
NewCheckBox4.TabOrder := 0;
NewCheckBox5.TabOrder := 1;
{ NewGroupBox3 }
NewGroupBox3 := TNewGroupBox.Create(WizardForm);
with NewGroupBox3 do
begin
Parent := WizardForm.SelectTasksPage;
Left := ScaleX(152);
Top := ScaleY(96);
Width := ScaleX(265);
Height := ScaleY(142);
Caption := 'NewGroupBox3';
end;
{ NewCheckBox6 }
NewCheckBox6 := TNewCheckBox.Create(WizardForm);
with NewCheckBox6 do
begin
Parent := NewGroupBox3;
Left := ScaleX(16);
Top := ScaleY(24);
Width := ScaleX(97);
Height := ScaleY(17);
Caption := 'NewCheckBox6';
end;
{ NewCheckBox7 }
NewCheckBox7 := TNewCheckBox.Create(WizardForm);
with NewCheckBox7 do
begin
Parent := NewGroupBox3;
Left := ScaleX(16);
Top := ScaleY(48);
Width := ScaleX(97);
Height := ScaleY(17);
Caption := 'NewCheckBox7';
end;
{ NewCheckBox8 }
NewCheckBox8 := TNewCheckBox.Create(WizardForm);
with NewCheckBox8 do
begin
Parent := NewGroupBox3;
Left := ScaleX(16);
Top := ScaleY(72);
Width := ScaleX(97);
Height := ScaleY(17);
Caption := 'NewCheckBox8';
end;
NewCheckBox6.TabOrder := 0;
NewCheckBox7.TabOrder := 1;
NewCheckBox8.TabOrder := 2;
NewGroupBox1.TabOrder := 2;
NewGroupBox2.TabOrder := 3;
NewGroupBox3.TabOrder := 4;
{ ReservationBegin }
// This part is for you. Add your specialized code here.
{ ReservationEnd }
end;
// Don't modify this section. It is generated automatically.
{ RedesignWizardFormEnd } // Don't remove this line!
procedure InitializeWizard();
begin
RedesignWizardForm;
end;
You cannot "make them work with Tasks". That does not make sense. The only purpose of Tasks is to automatically create the checkboxes on the "Select Additional Tasks" page. As you create the checkboxes programmatically, there's nothing that Tasks will give you on top of that.
If you want to use your custom checkboxes as Tasks, use Check parameter, instead of Tasks.
[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Check: IsCustomTask1Selected
[Code]
var
NewCheckBox1: TNewCheckBox;
function IsCustomTask1Selected: Boolean;
begin
Result := NewCheckBox1.Checked;
end;
For a complete solution, see How to split tasklist at tasks page of Inno Setup into multiple columns?
It works with the latest version of proper Inno Setup, with no need for an obsolete custom build of Inno Setup of doubtful origin.
Side notes:
I'd recommend you to use TNewCheckListBox, instead of TNewGroupBox with individual checkboxes.
5.5.1 is very old version that suffers many security issues.
Add a method for OnClickCheck event,
procedure InitializeWizard;
begin
WizardForm.TasksList.OnClickCheck := #TasksListClickCheck
end;
Then implement TasksListClickCheck method,
procedure TasksListClickCheck(Sender: TObject);
begin
/** Do whatever you want here **/
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