procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9','.']) then
    if Key <> #8 then
    Key := #0;
end;

解决方案 »

  1.   

    在你的keypress里的代码 
     if (key < '0') or (key > '9')  then begin
        key := #0;
      end;
      

  2.   

    procedure TfrmCbywcl.edtDnhKeyPress(Sender: TObject; var Key: Char);
    begin
      if not (key in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', char(VK_BACK),
        char(VK_RETURN), char(VK_LEFT), char(VK_UP), char(VK_RIGHT), char(VK_DOWN)]) then
        key := #0;
    end;
      

  3.   

    这样:
    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
        IF NOT (KEY IN ['0'..'9','.']) THEN KEY:=#0;
    end;
      

  4.   

    我也写一个:
      if (key<#48) or (key>#56) and (key<>8) and (key<>#46) then
         key:=#0;
      

  5.   

    procedure TForm1.edtHAHAKeyPress(Sender: TObject; var Key: Char);
    begin
        if not (Key in ['.',#8,'0','1','2','3','4','5','6','7','8','9']) then
          Key := #0;
    end;