我需要在Inno Setup的TInputQueryWizardPage
编辑框中仅允许输入字母数字字符。我怎么能这样做?
答案 0 :(得分:3)
要识别字母数字字符,我会使用IsCharAlphaNumeric
Windows API函数,并且在指定的输入编辑的OnKeyPress
事件中,如果它不是字母数字,我会吃掉密钥:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
function IsCharAlphaNumeric(ch: Char): BOOL;
external 'IsCharAlphaNumeric{#AW}@user32.dll stdcall';
procedure InputQueryEditKeyPress(Sender: TObject; var Key: Char);
begin
// if the currently pressed key is not alphanumeric, eat it by
// assigning #0 value
if not IsCharAlphaNumeric(Key) then
Key := #0;
end;
procedure InitializeWizard;
var
EditIndex: Integer;
InputPage: TInputQueryWizardPage;
begin
// create input query page and add one edit item
InputPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Description',
'SubCaption');
EditIndex := InputPage.Add('Name:', False);
// assign the OnKeyPress event method to our custom one
InputPage.Edits[EditIndex].OnKeyPress := @InputQueryEditKeyPress;
end;