Inno Setup - Create User Input Query Page with inp

2019-02-15 20:09发布

So, as the title says, I want to create a User Input Query Page (that's easy), but then I want the field to reject space character(s) and limit the input to no more than 15 characters (a bit more difficult for me). But then I need to write the input to a file, which I'm also not sure how to do.

Here's what my code looks like now:

var
  Page: TInputQueryWizardPage;

Procedure InitializeWizard();
Begin
  Page := CreateInputQueryPage(wpSelectTasks, 'Choose a Profile Name', 'This name will be used as your Profile Name', 'Please specify a name to be used as your Profile Name (make sure it''s unique), then click Next.');
  Page.Add('Name:', False);
  Page.Values[0] := 'YourName';
End;

function GetUserInput(param: String): String;
Begin
  result := Page.Values[0];
End;

As you can see, this code has no limitations for characters. That's the first thing I need help with.

My second problem is writing that value.

I am once again working with a non-standard INI file, not my fault. So this file is pretty much similar to a standard INI, it just doesn't have sections, just keys and values. Inno Setup's own INI section is of no use to me, since it won't allow input "outside" of a section, so I guess I'll have to treat it a text file(?).

I need to write the result as value to a key, named 'profile name'.

1条回答
Summer. ? 凉城
2楼-- · 2019-02-15 20:23

The length limit is easy, use TPasswordEdit.MaxLength property.

To prevent the user from typing a space, filter it in TEdit.OnKeyPress event.

But you need to check explicitly for spaces in the end anyway, because the spaces can also be pasted from clipboard for example. For a final check, use TWizardPage.OnNextButtonClick event.

var
  Page: TInputQueryWizardPage;

{ Prevent user from typing spaces ... }
procedure EditKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = ' ' then Key := #0;
end;

{ ... but check anyway if some spaces were sneaked in }
{ (e.g. by pasting from a clipboard) }
function ValidateInput(Sender: TWizardPage): Boolean;
begin
  Result := True;

  if Pos(' ', Page.Values[0]) > 0 then
  begin
    MsgBox('Profile Name cannot contain spaces.', mbError, MB_OK);
    Result := False;
  end;
end;

procedure InitializeWizard();
begin
  Page := CreateInputQueryPage(...);
  Page.OnNextButtonClick := @ValidateInput;
  Page.Add('Name:', False);
  Page.Edits[0].MaxLength := 15;
  Page.Edits[0].OnKeyPress := @EditKeyPress;
  Page.Values[0] := 'YourName';
  ...
end;

Another possibility is to implement the OnChange.
See Inno Setup Disable Next button when input is not valid.


As you already know, to use the entered value, access it via Page.Values[0].

Formatting the value for a custom INI file format is a completely different question, ask one.

查看更多
登录 后发表回答