delphi 的一段代码

来源:百度知道 编辑:UC知道 时间:2024/06/19 16:10:48
procedure TF_jhd.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if not (key in ['0'..'9','.',#8]) then key:=#0;
end;

啥意思?

StringGrid1的键盘按下事件
inherited; //继承
if not (key in ['0'..'9','.',#8]) then key:=#0; //如果键盘按下的那个键的键值不在0到9之间和“.” 和 #8 那么键盘按下的键转为#0(0即是键按下转为无效) 也就是说StringGrid1只接收键 0~9 和 .和 退格符,其它的键一律无效