//判断刚输入的一个字符是数字还是字母 procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if key in ['0'..'9'] then Caption:='数字哦!'; if key in ['a'..'z','A'..'Z'] then Caption:='字母哦!' end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (key in ['0'..'9','.',#13,#8]) then key:=#0 //只能用数字,".",回车(#13),退格(#8) end;
if not key in ['a'..'z','A'..'Z',#8] then do somethings
procedure xxxxKeyPress(Sender: TObject; var Key: Char); begin if not (Key in ['0'..'9', #3, #22, #24, #8, #9, #13, #46]) then Key := #0; end;可以输入数字,CTRL+C/V/X,以及小数点,ENTER 和backspace我也是学来的,谢谢那位大虾。
key:=#0在KeyPress里写
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key in ['0'..'9'] then
Caption:='数字哦!';
if key in ['a'..'z','A'..'Z'] then
Caption:='字母哦!'
end;
begin
if not (key in ['0'..'9','.',#13,#8]) then key:=#0
//只能用数字,".",回车(#13),退格(#8)
end;
begin
if not (Key in ['0'..'9', #3, #22, #24, #8, #9, #13, #46]) then
Key := #0;
end;可以输入数字,CTRL+C/V/X,以及小数点,ENTER 和backspace我也是学来的,谢谢那位大虾。