I have on CreateInputQueryPage, in that box user will type URL...Now i want to have Test button next to that text box so i can ping and validate that URL...is that possible ?
Using the Standard Support Functions, you are unable to do this.
You can call an external dll, which would allow you to do this.
You can also call COM interfaces, which would also allow you do to this.
Specifically you could use WinHTTPRequest COM object to perform this check.
You have a couple of options to deal with the validation. Both are demonstrated in the following script. The first is to create a button just for validation, the 2nd is to hook the Next Button and have it occur automatically before moving to the next page.
[Setup]
AppName='Test Script'
AppVerName='Test Script'
DefaultDirName={pf}\test
[Code]
const
InputQueryPageID = 100; //Determined by watching in Debugger.
var
Page : TInputQueryWizardPage;
procedure ClickEvent(Sender : TObject);
begin
MsgBox('Could Validate Here',mbInformation,MB_OK);
end;
procedure InitializeWizard();
var
Button : TButton;
begin
Page := CreateInputQueryPage(wpWelcome,
'Add URL', 'Test2','Test3');
Page.Add('URL:', False);
Button := TButton.Create(Page);
Button.Parent := Page.Surface;
Button.Caption := 'Button Text';
Button.Top := 100;
Button.Left := 10;
Button.OnClick := #ClickEvent;
end;
function NextButtonClick(CurrPageID: Integer) : Boolean;
begin
case CurrPageID of
InputQueryPageID : begin
MsgBox('Could Validate Here',mbInformation,MB_OK);
result := true; // Results of EXE Validation
end;
else result := true;
end;
end;
Related
I'm trying to write an installer in Inno Setup that includes a page where a TNewCheckListBox is created and then used to populate a selection of choices on the next page:
var
ListBox: TNewCheckListBox;
SelectedConfigs: array of Integer;
function ConfigurationPage(): Integer;
var
Page: TWizardPage;
I: Integer;
begin
Page := CreateCustomPage(wpSelectComponents, 'Select Configuration',
'Please select the configuration you would like to install to.');
ListBox := TNewCheckListBox.Create(Page);
ListBox.Parent := Page.Surface;
ListBox.Left := ScaleX(0);
ListBox.Top := ScaleY(0);
ListBox.Width := Page.SurfaceWidth;
ListBox.Height := Page.SurfaceHeight;
ListBox.BorderStyle := bsNone;
for I := 0 to GetArrayLength(ConfigurationNames) - 1 do
begin
ListBox.AddCheckBox(ConfigurationNames[I], '', 0, False, True, False, False, nil);
end;
ListBox.ItemIndex := 0;
Result := Page.ID;
end;
procedure PortSelectionPage(PageID: Integer);
var
Page: TWizardPage;
ArrayLength: Integer;
I: Integer;
begin
Page := CreateCustomPage(PageID, 'Select Port',
'Please select the port you want the configurations to receive on.');
for I := 0 to ListBox.Items.Count - 1 do
begin
Log(Format('ListBox[%d], %s is checked? %d', [I, ListBox.Items[I], ListBox.Checked[I]]));
if ListBox.Checked[I] then
begin
ArrayLength := GetArrayLength(SelectedConfigs);
SetArrayLength(SelectedConfigs, ArrayLength + 1);
SelectedConfigs[ArrayLength] := I;
Log(Format('Config %d was selected...', [I]));
end;
end;
end;
procedure InitializeWizard;
var
PageID: Integer;
begin
PageID := ConfigurationPage;
PortSelectionPage(PageID);
end;
The problem I'm having is that, regardless of the selections I make in the ConfigurationPage procedure, the SelectedConfigs array is not being updated and my debugging messages are showing that none of the options are selected. Before creating the PortSelectionPage procedure, the code lived on the CurStepChanged event handler so I'm not sure if the issue is with my having moved the code to a different page or if there's something else going on here. Do I need to force an update to the component or should I be using event handlers instead? If so, how would I implement one for this usecase?
Your whole code is executed from InitializeWizard event function. Hence even before the installer wizard is shown.
You have to query the checkbox states only after the user changes them. For example, from some of these events:
NextButtonClick
CurStepChanged
CurPageChanged
I have made a quick installer and in some PC I have found problems when installing. I have "serial number" system and when I press "Next" it gives me an error
You must enter a name
and then:
Cannot focus a disabled or invisible window
But in many other PCs with same SO this works normal. This is the code that I am using:
[Setup]
WizardStyle=modern
UserInfoPage=yes
[Code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpUserInfo then begin
WizardForm.UserInfoOrgLabel.Hide();
WizardForm.UserInfoOrgEdit.Hide();
WizardForm.UserInfoNameLabel.Hide();
WizardForm.UserInfoNameEdit.Hide();
end;
end;
// Presence of the CheckSerial event function displays the serial number box.
// But here we accept any non-empty serial.
// We will validate it only in the NextButtonClick,
// as the online validation can take long.
function CheckSerial(Serial: String): Boolean;
begin
Result := (Serial <> '');
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
WinHttpReq: Variant;
Url: string;
begin
Result := True;
if CurPageID = wpUserInfo then
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
Url := 'Link that i use to check the serial number' +
WizardForm.UserInfoSerialEdit.Text;
WinHttpReq.Open('GET', Url, False);
WinHttpReq.Send('');
// Depending on implementation of the server,
// use either HTTP status code (.Status)
// or contents of returned "page" (.ResponseText)
// Here we use the HTTP status code:
// 200 = serial is valid, anything else = serial is invalid,
// and when invalid, we display .ResponseText
Result := (WinHttpReq.Status = 200);
if not Result then
MsgBox(WinHttpReq.ResponseText, mbError, MB_OK);
end;
end;
With UserInfoPage enabled, filling in the "User name" box is mandatory. The box is pre-filled with a value of RegisteredOwner registry value. If that value happens to be empty, and consequently the box, you cannot leave the page, until you fill it in manually. You get the "You must enter a name" error and Inno Setup moves the focus to the box. That fails with "Cannot focus a disabled or invisible window", as you have the box hidden.
If you do not care about the username, just fill in some dummy value:
WizardForm.UserInfoNameEdit.Text := 'foo';
I have an Information page, the page that that is activated with infobefore file:
[Setup]
InfoBeforeFile=infobefore.txt
I want to:
Add a checkbox (or a couple of checkboxes), that the user has to check to show that he has paid attention to the information.
The user should only be allowed to proceed when he checks the checkboxes right. I think of disabling the Next button or showing a messagebox, whatever is easier.
Is there an easy way to do this?
Just add a new checkbox on the InfoBeforePage page. And update the NextButton state based on the check box state.
[Setup]
InfoBeforeFile=infobefore.txt
[Code]
var
InfoBeforeCheck: TNewCheckBox;
procedure CheckInfoBeforeRead;
begin
{ Enable the NextButton only if InfoBeforeCheck is checked or }
{ installer is running in the silent mode }
WizardForm.NextButton.Enabled := InfoBeforeCheck.Checked or WizardSilent;
end;
procedure InfoBeforeCheckClick(Sender: TObject);
begin
{ Update state of the Next button, whenever the InfoBeforeCheck is toggled }
CheckInfoBeforeRead;
end;
procedure InitializeWizard();
begin
InfoBeforeCheck := TNewCheckBox.Create(WizardForm);
InfoBeforeCheck.Parent := WizardForm.InfoBeforePage;
{ Follow the License page layout }
InfoBeforeCheck.Top := WizardForm.LicenseNotAcceptedRadio.Top;
InfoBeforeCheck.Left := WizardForm.LicenseNotAcceptedRadio.Left;
InfoBeforeCheck.Width := WizardForm.LicenseNotAcceptedRadio.Width;
InfoBeforeCheck.Height := WizardForm.LicenseNotAcceptedRadio.Height;
InfoBeforeCheck.Caption := 'I swear I read this';
InfoBeforeCheck.OnClick := #InfoBeforeCheckClick;
{ Make the gap between the InfoBeforeMemo and the InfoBeforeCheck the same }
{ as the gap between LicenseMemo and LicenseAcceptedRadio }
WizardForm.InfoBeforeMemo.Height :=
((WizardForm.LicenseMemo.Top + WizardForm.LicenseMemo.Height) -
WizardForm.InfoBeforeMemo.Top) +
(InfoBeforeCheck.Top - WizardForm.LicenseAcceptedRadio.Top);
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpInfoBefore then
begin
{ Initial state of the Next button }
CheckInfoBeforeRead;
end;
end;
Here is the script I'm using on Inno Setup. It is my first script, please understand if I'm asking something obvious.
It seems that the variable ServerAddress never has a value, even if I fill the input field. It looks like Page.Values[0] always returns an empty result. What is wrong with my code?
As you can see, I have made a test with a testvar variable to exclude it was a matter of variable scope, but it's not the case.
[Code]
var
Page: TInputQueryWizardPage;
ServerAddress: String;
testvar: String;
procedure InitializeWizard();
begin
Page := CreateInputQueryPage(wpWelcome,
'Server Informations', '',
'Please specify the IP address, then click Next.');
{ Add items (False means it's not a password edit) }
Page.Add('IP Address:', False);
ServerAddress := Page.Values[0];
testvar := 'testvalue';
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then begin
MsgBox(ExpandConstant('{app} '+testvar+' : '+ServerAddress),mbInformation,MB_OK);
SaveStringToFile(ExpandConstant('{app}')+'\config.txt', 'test'+ServerAddress, True);
end;
end;
The InitializeWizard event function is called (and finishes) before the wizard window is even shown.
So a value (that the user will enter in the future) can hardly be known at that point. You have to read the value only after the custom page is shown. Like in your CurStepChanged(ssPostInstall):
procedure CurStepChanged(CurStep: TSetupStep);
var
ServerAddress: string;
begin
if CurStep = ssPostInstall then
begin
{ This is the right time to read the value }
ServerAddress := Page.Values[0];
SaveStringToFile(ExpandConstant('{app}') + '\config.txt', ServerAddress, True);
end;
end;
Is the following code it right or not and, if it is wrong, please correct it.
Note: I want to open the file with "WordPad.exe" not with "Microsoft Office Word" until if "Microsoft Office Word" is the default program.
My code:
function InitializeSetup: Boolean;
var
S: AnsiString;
begin
// Show the contents of Readme.txt (non Unicode) in a message box
ExtractTemporaryFile('Info.rtf');
Result := True;
end;
procedure AboutButtonOnClick(Sender: TObject);
var
ErrorCode: Integer;
begin
ShellExec('open', ExpandConstant('{tmp}\Info.rtf'), '', '', SW_SHOWNORMAL, ewNoWait,
ErrorCode);
end;
ShellExec('open','Documentname'....); will open with the program associated with the extension of the file. If there is no program associated it will prompt you to select which program you want to view it with.
You could look for WordPad.exe and if it's found you could call ShellExec using the WordPad.EXE directly. Then pass the documentName as a parameter.
Updated with function to do this
procedure OpenDocumentInWordPad(Document : String);
var
WordPad : String;
ErrorCode : Integer;
begin
// Typical Location on XP and later.
WordPad := ExpandConstant('{pf}') + '\Windows NT\Accessories\WordPad.exe'
// Find word pad
if Not FileExists(WordPad) then
begin
// Location in Windows 95/98
WordPad := ExpandConstant('{pf}') + '\Accessories\WordPad.exe'
if Not FileExists(WordPad) then
begin
// Fall back to anything associated with document.
WordPad := Document;
Document := '';
end;
end;
if not ShellExec('open',WordPad,Document,'',SW_SHOW,ewNoWait,ErrorCode) then
begin
MsgBox(SysErrorMessage(ErrorCode),mbError,MB_OK);
end;
end;