【问题标题】:Inno Setup restrict some special characters on key pressInno Setup 限制按键时的一些特殊字符
【发布时间】:2018-09-21 13:09:50
【问题描述】:

我正在尝试根据我的要求限制输入框中某些特殊字符的按键,我正在使用以下过程来做同样的事情。

procedure RestrictKeyPress(Sender: TObject; var Key: Char);
var
  KeyCode: Integer;
begin
  { Restrict special characters @, ^, *, \ }
  KeyCode := Ord(Key);
  if ((KeyCode = 32) or (KeyCode >= 64) or (KeyCode <= 94) or (KeyCode <= 42) or (KeyCode <= 92)) then
    Key := #0;
end;

我像这样在InitializeWizard 中调用这个过程

PageConfig.Edits[1].OnKeyPress := @RestrictKeyPress;

但是当我测试这个时,按键对任何键都不起作用。我试图只限制下面提到的键和空间。

@、^、*、\

【问题讨论】:

  • 非常感谢肯。愚蠢的错误。

标签: inno-setup pascalscript


【解决方案1】:

你的逻辑完全错误。 :-) 让我们看看:

if ((KeyCode = 32)          { Ok so far }
  or (KeyCode >= 64)        { Oops. Killing every key above 63 }
  or (KeyCode <= 94)        { And every key below 95 }
  or (KeyCode <= 42)        { And (redundantly) every key below 43 }
  or (KeyCode <= 92)) then  { And (redundantly) every key below 93 }

您也不需要将Key 转换为数字。

改用简单的集合:

if (Key in ['@', '^', '*', '\', #32]) then  { #32 is space }
  Key := #0;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 2012-11-05
    • 2014-10-06
    • 2019-03-28
    相关资源
    最近更新 更多