Inno Setup-创建具有输入长度和格式限制的用户输入查询页面并使用输入 [英] Inno Setup - Create User Input Query Page with input length and format limit and use the input
问题描述
因此,正如标题所述,我想创建一个用户输入查询页面(这很简单),但是随后我希望该字段拒绝空格字符并将输入限制为不超过15个字符(有点对我来说更困难).但是然后我需要将输入写到文件中,我也不知道该怎么做.
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.
我再次使用非标准的INI文件,不是我的错.因此,该文件与标准INI非常相似,只是没有节,只有键和值. Inno Setup自己的INI部分对我没有用,因为它不允许在部分的外部"输入,因此我想我必须将其视为文本文件(?).
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'.
推荐答案
长度限制很简单,请使用TPasswordEdit.MaxLength
属性.
The length limit is easy, use TPasswordEdit.MaxLength
property.
为防止用户键入空格,请在TEdit.OnKeyPress
事件中对其进行过滤.
To prevent the user from typing a space, filter it in TEdit.OnKeyPress
event.
但是无论如何,您最终都必须明确检查空格,因为例如也可以从剪贴板粘贴空格.对于最终检查,请使用TWizardPage.OnNextButtonClick
事件.
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;
另一种可能性是实施OnChange
.
请参见输入无效时,Inno Setup禁用下一步"按钮.
Another possibility is to implement the OnChange
.
See Inno Setup Disable Next button when input is not valid.
您已经知道,要使用输入的值,请通过Page.Values[0]
进行访问.
As you already know, to use the entered value, access it via Page.Values[0]
.
格式化自定义INI文件格式的值是一个完全不同的问题,问一个.
这篇关于Inno Setup-创建具有输入长度和格式限制的用户输入查询页面并使用输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!