Inno Setup - 创建具有输入长度和格式限制的用户输入查询页面并使用输入

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

所以,正如标题所说,我想创建一个用户输入查询页面(这很简单),但是我希望该字段拒绝 space 个字符并将输入限制为不再超过 15 个字符(对我来说有点困难)。但是我需要将输入写入一个文件,我也不知道该怎么做。

这是我的代码现在的样子:

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;

如您所见,这段代码没有字符限制。这是我需要帮助的第一件事。

我的第二个问题是写入那个值。

我再次使用 non-standard INI 文件,这不是我的错。所以这个文件与标准 INI 非常相似,只是没有部分,只有键和值。 Inno Setup 自己的 INI 部分对我没有用,因为它不允许输入部分 "outside",所以我想我必须将其视为文本文件(?)。

我需要将结果作为值写入名为 'profile name' 的键。

长度限制很简单,用TPasswordEdit.MaxLength 属性.

要防止用户键入 space,请在 TEdit.OnKeyPress 事件中对其进行过滤。

但是无论如何你最终都需要明确检查 spaces,因为 spaces 也可以从剪贴板粘贴。对于最终检查,请使用 TWizardPage.OnNextButtonClick 事件。

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;

另一种可能性是实施OnChange
参见


如您所知,要使用输入的值,请通过 Page.Values[0] 访问它。

格式化自定义 INI 文件格式的值是一个完全不同的问题,ask one