界面上有N个edit我想让每个edit都只能输入 0-9的数字,我又不想在每个edit的keypress里写代码,
我想做成一个过程,每个edit的keypress里调用这个过程就可以了。
要如何做啊?目前我的判断代码:
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9']) then
begin
Key := #0;
end;
end;
我想做成一个过程,每个edit的keypress里调用这个过程就可以了。
要如何做啊?目前我的判断代码:
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9']) then
begin
Key := #0;
end;
end;
解决方案 »
- delphi 分割字符串的问题
- 分钟转换成小时的问题
- 大家看看这个sql语句错在哪里?
- FT,请教关于类的protected问题????
- 怎么样用一个按钮当按下时数据库中表的当前记录往前(或往后)移一个位置.
- WORD出错,请看 120分,因我是用DELPHI的,,所以贴在这儿。。急。》》》》》》》
- 请问那里有OCR的DLL
- oracle 备份导入程序
- 我要做一个继承TButton的控件,只是不需要Onclick事件,如何屏蔽?
- 一个小问题。请大家伙儿给俺指点指点.......
- 关于delphi7提取部分字符的问题???
- 为什么idhttp在不用cookiemanager的情况下要get两次才有cookie值?
var
i: integer;
begin
for i := 0 to ComponentCount - 1 do
if Components[i] is TEdit then
TEdit(Components[i]).OnKeyPress := myKeyPress;
//......
end;//记得在类中声明
procedure TForm1.myKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9']) then
begin
Key := #0;
end;
end;
2.全部选好后,按F11显示属性栏,在OnKeyPress事件中填入你的myKeyPress。注: 第二步实际上就是操作所有edit了。
请注明版本,在D7中无此属性
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9']) then
begin
Key := #0;
end;
end;
其他的EDIT的KeyPress都引用edt1KeyPress
当然,如果版本支持3L和4L所说的属性设置那更方便了
type
TEdit = class(StdCtrls.TEdit)
private
procedure WMChar(var Message: TWMChar); message WM_CHAR;
end; TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TEdit }procedure TEdit.WMChar(var Message: TWMChar);
begin
if (Message.CharCode >= 48) and (Message.CharCode <= 57) then
inherited;
end;
procedure TEdit.WMChar(var Message: TWMChar);
begin
if ((Message.CharCode >= 48) and (Message.CharCode <= 57)) or
(Message.CharCode = VK_BACK) then
inherited;
end;