OnKeyPress事件
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (key in ['0'..'9']=false) and (word(key)<>vk_back) then
begin
key:=#0;
end;
end;
注:word(key)<>vk_back 用于判断删除键
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if (key in ['0'..'9']=false) and (word(key)<>vk_back) then
begin
key:=#0;
end;