gpt4 book ai didi

delphi - 如何禁用delphi中的某些键

转载 作者:行者123 更新时间:2023-12-03 19:00:57 24 4
gpt4 key购买 nike

我已将以下代码添加到我的程序中,据我所知,该代码必须禁止输入字母。我将表单的 KeyPreview 属性设置为 True,接下来我添加了这段代码

procedure FormKeyPress(Sender: TObject; var Key: Char) ;

定义为

 procedure TFibo.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key in ['a'..'z'] then Key := #0
end;

这似乎不起作用,因为我可以在表单的编辑组件中输入 a-z;我做错了什么?

这是我的程序代码

 unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TFibo = class(TForm)
lblInput: TLabel;
edtInput: TEdit;
procedure FormKeyPress(Sender: TObject; var Key: Char) ;
end;

var
Fibo: TFibo;

implementation

{$R *.dfm}

procedure Tfibo.FormKeyPress(Sender:TObject;var Key:char);
begin
if Key in ['a'..'z', 'A'..'Z'] then
Key := #0
end;

end.

最佳答案

您的代码工作正常,因为它阻止了“a”到“z”。也许您的问题是它不会阻止大写字符。为此,您需要:

if Key in ['a'..'z', 'A'..'Z'] then
Key := #0

关于delphi - 如何禁用delphi中的某些键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6490007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com