I want to make a wizard. When the user choose yes, then the page x should follow. When the user choose no, then the page y should follow. At the moment it is only working for me with static pages, so it does not matter, what the user chooses always the same page follows... how can I change this? Please have somebody an idea?
Here is an extract:
ExistPage := CreateInputOptionPage(OldPage.ID,
'', '', 'If you choose "Yes" then the package will be installed automatically with this setup',True, False);
// Add items
ExistPage.Add('Yes');
ExistPage.Add('No');
// Set initial values (optional)
ExistPage.SelectedValueIndex := 0;
TexPage := CreateInputDirPage(ExistPage.ID,
'Root installation directory', 'Please select installation directory',
'',
True, 'New Folder');
TexPage.Add('');
// Set initial value (optional)
TexPage.Values[0] := ExpandConstant('C:\');
When you create your page you can store the page ID into a variable:
// InitializeWizard is called when the wizard is about to begin.
// This is where we add any custom pages into the installation process.
// The relevant XXX_CreatePage methods should be defined BEFORE this method.
procedure InitializeWizard();
begin
// Add the Application Settings page just after the Selected Tasks page
idAppSettingsPage := AppSettings_CreatePage(wpSelectTasks)
end;
If you were to cache the result of your users radio choice into a public variable then you might be able to use this:
function ShouldSkipPage(PageID: Integer): Boolean;
begin
// We don't want to show the select dir, select program group or application settings
// pages if we are upgrading.
if ((PageID = wpSelectDir) or (PageID = idAppSettingsPage) or (PageID = wpSelectProgramGroup)) then
Result := bIsUpgrading
else
Result := False;
end;
This is something I have used in my setup to selectively show pages during the install process. I am just not sure how you check for a custom page ID.
I am just showing the mechanics. If you know you are now about to show page Y, you can decide to show it if variable AA was set to 1. Make sense?
Related
How to customize last page (wpFinished) to only have a message, but keep the bottom buttons, like this:
I don't want the image on the left that is there by default.
I was trying to create new page, but don't know how to hide the default finished page or add bottom buttons (Back, Finished, Cancel) on new page.
Hide the WizardBitmapImage2 control and extend remaining controls accordingly.
Something like this:
[Code]
procedure ExtendFinishedPageControl(Control: TControl);
begin
Control.Left := Control.Left - WizardForm.WizardBitmapImage2.Width;
Control.Width := Control.Width + WizardForm.WizardBitmapImage2.Width;
end;
procedure InitializeWizard();
begin
WizardForm.WizardBitmapImage2.Visible := False;
ExtendFinishedPageControl(WizardForm.RunList);
ExtendFinishedPageControl(WizardForm.NoRadio);
ExtendFinishedPageControl(WizardForm.YesRadio);
ExtendFinishedPageControl(WizardForm.FinishedLabel);
ExtendFinishedPageControl(WizardForm.FinishedHeadingLabel);
end;
I have a requirement to skip a page when only a particular component is selected in the component selection page. Please look at the below image
[Components]
Name: DBS\TRACE; Types: DBS TBLWOS; Description: DBS Tracing Bodylife Database;
The requirement is to skip a page when the option "DBS Tracing Bodylife Database" (highlighted in the image) alone is selected and clicked on Next button. If I select only that option, I am successfully able to skip the page using below code.
if PageID = PageToBeSkipped.ID then begin
Result := not (IsComponentSelected('not DBS\TRACE'));
end;
But If I select any other additional component along with the "DBS Tracing Bodylife Database" from this page which is nearly 20, the page should not be skipped. The above code skips the page if any additional component is selected too.
How can I handle this?
Thanks in advance!
To test if any component, except one specific, is selected, you can use WizardSelectedComponents function (which returns a comma-separated list of selected components).
function ShouldSkipPage(PageID: Integer): Boolean;
begin
Result := False;
if PageID = PageToBeSkipped.ID then
begin
Result := (CompareText(WizardSelectedComponents(False), 'DBS,DBS\TRACE') = 0);
end;
end;
Note that the WizardSelectedComponents returns even "partially" selected components groups.
I am creating an Inno Setup installer that is a little non traditional. I am setting Uninstallable=no but I still need to be able to remember what the user selected for the type of install if they reinstall in the future. I thought about writing the type out to a file which I was able to do. I am not sure how to set the type when the installer is run the next time however. Here is my code for storing the type.
procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep = ssDone) then
SaveStringToFile('{app}\type.dat', WizardSetupType(false), false);
end;
I know how to read this back in, but I am not sure how to set the type.
Edit:
Here is the new code
procedure CurPageChanged(CurPageID: Integer);
begin
{ We need to manually store and restore the install type since Uninstallable=no }
if (CurPageID = wpSelectComponents) then
WizardForm.TypesCombo.ItemIndex := GetIniInt('Settings', 'InstallType', 0, 0, 3, ExpandConstant('{app}\settings.ini'));
if (CurPageID = wpInstalling) then
SetIniInt('Settings', 'InstallType', WizardForm.TypesCombo.ItemIndex, ExpandConstant('{app}\settings.ini'));
end;
Save WizardForm.TypesCombo.ItemIndex instead of the WizardSetupType and set it back when restoring the selection.
After restoring the WizardForm.TypesCombo.ItemIndex you have to call the WizardForm.TypesCombo.OnChange to update the components selection.
I'd also suggest you use INI file functions SetIniInt and GetIniInt instead of the SaveStringToFile.
Store:
SetIniInt('Settings', 'InstallType', WizardForm.TypesCombo.ItemIndex,
ExpandConstant('{app}\settings.ini'));
Restore:
WizardForm.TypesCombo.ItemIndex :=
GetIniInt('Settings', 'InstallType', 0, 0, 3, ExpandConstant('{app}\settings.ini'));
{ The OnChange is not called automatically when ItemIndex is set programmatically. }
{ We have to call it to update components selection. }
WizardForm.TypesCombo.OnChange(WizardForm.TypesCombo);
For an explanation of the last code line, see What does it mean if we type WizardForm.TypesCombo.OnChange(WizardForm.TypesCombo) in Inno Setup?
An installer I'm working on does most of its work in the PrepareToInstall function, as everything I need to do might fail, and therefore this is the appropriate place to handle these things in case they do fail. Any failure can be automatically reported by passing the error message in the function's result. There are only 3 small files which the installer actually copies over.
The problem is that the wizard seems to freeze (or not respond rather) during this function, just showing a blank page titled "Preparing to install..." while in reality, it's going through my install process.
I would like to show the progress to the user with a simple procedure ShowProgress(const S: String); which shows the user what it's actually doing. How can I do this?
This is how I'm doing my install, where I'd like to wrap each call to Log()...
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
R: Integer;
begin
Result:= '';
try
Log('Doing this...');
R:= DoThis;
case R of
0: begin
Result:= '';
end;
1: begin
Result:= 'Error message 1 was raised while doing this.';
end;
else begin
Result:= 'Unexpected error doing this: ' + IntToStr(R);
end;
end;
if Result = '' then begin
Log ('Doing that...');
R:= DoThat;
case R of
0: begin
Result:= '';
end;
1: begin
Result:= 'Error message 1 was raised while doing that.';
end;
else begin
Result:= 'Unexpected error doing that: ' + IntToStr(R);
end;
end;
end;
if Result = '' then begin
Log ('Doing something else...');
R:= DoSomethingElse;
case R of
0: begin
Result:= '';
end;
1: begin
Result:= 'Error message 1 was raised while doing something else.';
end;
else begin
Result:= 'Unexpected error doing something else: ' + IntToStr(R);
end;
end;
end;
//A few more blocks like above
//Error logging
if Result <> '' then begin
Log('FAILURE: '+Result);
end;
except
Result:= 'EXCEPTION';
Log('EXCEPTION');
end;
end;
I mixed all your answers guys and I found another possible solution to this question.
I know this is not a so called 'elegant solution'.
Anyway it is a quick solution that can avoid you to develop a separated DLL with custom controls managing the communication between the installer and the DLL.
The following approach describe how to create a custom Page that is a copy of the Page Inno Setup shows during PrepareToInstall setup phase.
This copy must have the same look and feel of the original one plus a progress bar and a label that developer can use to indicate the current step of the PrepareToInstall setup phase.
Let's see some code.
First of all, prepare the custom Page:
[Code]
var
PrepareToInstallWithProgressPage : TOutputProgressWizardPage;
Now define PrepareToInstall function to add our custom stuff:
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ResultCode: Integer;
begin
PrepareToInstallWithProgressPage.SetProgress(0, 0);
PrepareToInstallWithProgressPage.Show;
try
// First preinstallation step: suppose to kill currently app you are going to update
PrepareToInstallWithProgressPage.SetText('Exiting MyApp Running Instances'), '');
ExecuteCmd('taskkill', '/F /IM MyApp');
// Set progress bar to 10%
PrepareToInstallWithProgressPage.SetProgress(1, 10);
// Second preinstallation step
// DoSomething usefull...
// Set progress bar to 20% after done
PrepareToInstallWithProgressPage.SetProgress(2, 10);
// ...do other preinstallation steps till the end
PrepareToInstallWithProgressPage.SetProgress(10, 10);
finally
PrepareToInstallWithProgressPage.Hide;
end;
end;
At this installation phase we completed the steps for prepare to install phase so the default PrepareToInstall Page of Inno Setup is shown for a while.
Now, the user probably cannot understand that the page changes because our PrepareToInstallWithProgressPage has the same look and feel of the original one.
In order to let our page has the same look and feel we can use SetupMessage function to get the 2 strings of the original Inno Setup PrepareToInstall page.
Using SetupMessage we can avoid to duplicate and localize strings for our custom page to copy the originals.
Just like this:
procedure InitializeWizard;
var
A: AnsiString;
S: String;
begin
// The string msgWizardPreparing has the macro '[name]' inside that I have to replace with the name of my app, stored in a define constant of my script.
S := SetupMessage(msgPreparingDesc);
StringChange(S, '[name]', '{#MY_APPNAME}');
A := S;
PrepareToInstallWithProgressPage := CreateOutputProgressPage(SetupMessage(msgWizardPreparing), A);
end;
I hope this help.
Have a look at the CodeDlg.iss example script included with Inno, in particular at the code that uses CreateOutputProgressPage.
This page type allows you to show a status message and/or a progress bar while you are performing other actions. And it automatically pumps messages whenever you change the progress label/value to ensure that the user sees the correct status.
It is intended for precisely this kind of code.
The code written in the PrepareToInstall function blocks the Windows message pump from processing, rendering the wizard form non-responsive. If many controls are needed to be visible in this screen, showing perhaps a progress bar and list of steps to take, this can be done with a form inside of a DLL. Make sure there is a thread in this DLL which does the actual install process, and only update the GUI to display the status to the user. This DLL form may overlay the wizard, or may even be embedded inside of the wizard in a custom wizard page, for example. The idea is to move your install code from the PrepareToInstall function to within this thread, and only then will you be able to achieve a fully responsive GUI during this process. From the PrepareToInstall function, there should be just one DLL call to initiate the install process, which in turn shows the form from the DLL.
The result may look something like this (in the works):
Is it possible to conditionally disable or hide edit boxes from a TInputQueryWizardPage input page (page created by using CreateInputQueryPage function) ?
I have 4 edit boxes and I need to disable/hide the last two of them, based on the input from the previous wizard page. How can I do it ?
You can access them through the TInputQueryWizardPage.Edits indexed property:
[Code]
var
FirstEditIndex: Integer;
SecondEditIndex: Integer;
InputPage: TInputQueryWizardPage;
procedure InitializeWizard;
begin
InputPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Dscription', 'SubCaption');
// the Add method returns the Index of the just added edit box, and
// you need to store those indexes to access the edit boxes later on
FirstEditIndex := InputPage.Add('Name:', False);
SecondEditIndex := InputPage.Add('Surname:', False);
// access the edits through the stored indexes; in your case this will
// happen in the other event, so take this script as a showcase
InputPage.Edits[FirstEditIndex].Enabled := False;
InputPage.Edits[SecondEditIndex].Visible := False;
end;