Procedure KeyFilter(var key:Char); begin if (not (Key in['a'..'z'])) and (not (Key in['A'..'Z'])) and (not (Key in['0'..'9'])) and (not (Key in['-'])) and (not (Ord(Key)in [8,13,27,3,22,24])) then //8-退格,13-回车,27-ESC,3-Ctrl+C,22-Ctrl+V,24-Ctrl+X begin MsgBox('请输入有效字符:A-Z,0-9,-','提示信息',MB_ICONINFORMATION); Key :=#0; end; if Key in['a'..'z'] then Key := Chr(Ord(key)-32); end;