Inno Setup - Create User Input Query Page with input length and format limit and use the input

后端 未结 1 1572
南旧
南旧 2020-12-18 16:46

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

相关标签:
1条回答
  • 2020-12-18 17:22

    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.

    0 讨论(0)
提交回复
热议问题