Inno Setup: How to show (hide/unhide) password on checkbox checked - inno-setup

I am adding a checkbox to my input query page to use it to show me the password uncovered, when is checked. But I don't know how to do that.
I already created the following procedure. But this procedure does not change me the true false value on add input. This procedure adds me new textbox that do the job.
Could you please help me?
procedure SPCheckBoxChecked(Sender: TObject);
begin
if Assigned(SPCheckBox) then
begin
if SPCheckBox.Checked then
CredentialsPage.Add('Password:', False)
if not SPCheckBox.Checked then
CredentialsPage.Add('Password:', True)
end;
end;

Use TPasswordEdit.Password property:
[Code]
var
InputQueryPage: TInputQueryWizardPage;
procedure ShowPasswordCheckClick(Sender: TObject);
begin
InputQueryPage.Edits[0].Password := not TNewCheckBox(Sender).Checked;
end;
procedure InitializeWizard();
var
ShowPasswordCheck: TNewCheckBox;
begin
InputQueryPage := CreateInputQueryPage(
wpWelcome, 'Password prompt', 'Please enter your password', '');
InputQueryPage.Add('Password:', True);
ShowPasswordCheck := TNewCheckBox.Create(WizardForm);
ShowPasswordCheck.Parent := InputQueryPage.Surface;
ShowPasswordCheck.Top :=
InputQueryPage.Edits[0].Top + InputQueryPage.Edits[0].Height + ScaleY(8);
ShowPasswordCheck.Height := ScaleY(ShowPasswordCheck.Height);
ShowPasswordCheck.Caption := '&Show password';
ShowPasswordCheck.OnClick := #ShowPasswordCheckClick;
end;

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.

Update controls based on edit box change in Inno Setup

How can I capture changes in text box value?
I'm researching how to use OnChange event function but i don't know how to use it.
[Code]
var
Page: TInputQueryWizardPage;
procedure InitializeWizard();
begin
Page := CreateInputQueryPage(wpWelcome,
'Personal Information', 'Who are you?',
'Please specify your name and the company for whom you work, then click Next.');
Page.Add('Server:', False);
Page.Add('NAME:', False);
Page.Add('LOCATION:', False);
Page.Values[0] := ('test0');
Page.Values[1] := ('test1');
Page.Values[2] := ('string')+Page.Values[0]+('string')+Page.Values[1];
end;
Handle OnChange event like:
var
Page: TInputQueryWizardPage;
procedure EditChange(Sender: TObject);
begin
Page.Values[2] := 'string' + Page.Values[0] + 'string' + Page.Values[1];
end;
procedure InitializeWizard();
begin
Page := CreateInputQueryPage(...);
Page.Add('Server:', False);
Page.Add('NAME:', False);
Page.Add('LOCATION:', False);
Page.Values[0] := 'test0';
Page.Values[1] := 'test1';
Page.Edits[0].OnChange := #EditChange;
Page.Edits[1].OnChange := #EditChange;
{ Reflect the initial values }
EditChange(nil);
end;
Note that the Edit[2] can be changed by the user, so maybe you want to set it read only.
Page.Edits[2].ReadOnly := True;
Page.Edits[2].Color := clBtnFace;
Or you may actually want to use TLabel instead.

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;

INNO setup - CreateInputQueryPage after install has completed returns initial values, not the ones edited

I am new to INNO and getting better every but I am having a problem with the CreateInputQueryPage that is running after the install is complete. It is returning the initial values that I put in as the defaults, not the edited values the user has edited.
Here is the code that creates the page. This seems to be fine.
procedure InitializeWizard();
var
ret : boolean;
begin
SvrSetup := CreateInputQueryPage(wpInfoAfter,
'i2x Server setup', '',
'Please specify your Company name, Listener host name and Port. then click Next.');
SvrSetup.Add('Company name:', False);
SvrSetup.Add('Listener host name:', False);
SvrSetup.Add('Port:', False);
SvrSetup.Values[1] := 'computer name'
SvrSetup.Values[2] := '5551';
end;
I run this code on the NEXTBUTTONCLICK event to validate my input
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := true;
{ Validate certain pages before allowing the user to proceed }
if CurPageID = SvrSetup.ID then
begin
if SvrSetup.Values[0] = '' then begin
MsgBox('You must enter company name.', mbError, MB_OK);
Result := False;
end;
if SvrSetup.Values[1] = '' then begin
MsgBox('You must enter listner host.', mbError, MB_OK);
Result := False;
end;
if SvrSetup.Values[2] = '' then begin
MsgBox('You must enter listner port.', mbError, MB_OK);
Result := False;
end;
end;
end;
Now when the install is over but before the final page I do this.
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
WriteXML;
end;
end;
And WriteXML is this.
procedure WriteXML;
var
FileData: String;
begin
FileData := ''
LoadStringFromFile(ExpandConstant('{app}\EMailer\EMailer.exe.config'), FileData);
StringChange(FileData, '!OVERRIDE_COMP!',ExpandConstant('{code:GetEmailerCompany}'));
SaveStringToFile(ExpandConstant('{app}\EMailer\EMailer.exe.config'), FileData, False);
end;
With the value I need to insert into the XML as code:GetEmailerCompanyas
function GetEmailerCompany(Param: String): String;
begin
// Return the company for email
Result := SvrSetup.Values[0];
end;
Aagain, It is returning the initial values that I put in as the defaults, not the edited values the user has edited. What am I missing?
Thanks

Resources