if (Pos(Key,'1234567890.')=0) and (key=vk_return) then 
      begin
        Key := Chr(0);
        ShowMessage('不能输入非数字的字符!');
      end;//if
 这样写不对。

解决方案 »

  1.   

    if  not((key in ['0'..'9']) or (key  in[#13, #8])) then
      Key := #0;
      

  2.   

    if  not((key in ['0'..'9', #13, #8]) ) then
      Key := #0;
      

  3.   

    同意楼上,不过楼主要注意是在keypress事件中执行
    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
    if  not((key in ['0'..'9', #13, #8]) ) then
      Key := #0;
    end;