key preessif key in ['0',['1],..........................] then key=#0 endif
if key in ['0'..'9'] then key := #0;
on key preessif Key not in ['0'..'9','a'..'z','A'..'Z',#8] then Key := #0
得~~ 来晚一步 #8 就是键盘上地 Back Space 键。
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not(key in ['0'..'9']) then begin if not(key in ['a'..'z']) then begin if not(key in ['A'..'Z']) then begin Key:=chr(0); showmessage('输入错误,请输入数字或字母'); end; end; end; end; end.
或这样也可:procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (key in ['0'..'9','a'..'z','A'..'Z',#8]) then begin Key := #0; showmessage('输入错误,请输入数字或字母'); end; end; end.
key=#0
endif
#8 就是键盘上地 Back Space 键。
begin
if not(key in ['0'..'9']) then
begin
if not(key in ['a'..'z']) then
begin
if not(key in ['A'..'Z']) then
begin
Key:=chr(0);
showmessage('输入错误,请输入数字或字母');
end;
end;
end;
end;
end.
begin
if not (key in ['0'..'9','a'..'z','A'..'Z',#8]) then
begin
Key := #0;
showmessage('输入错误,请输入数字或字母');
end;
end;
end.