请问如何限制用户在edit文本框内只能输入数字或小数?
或者如何判断出用户在edit文本框中输入的不是数字或小数?
(例如只能输入15,12.36等等)谢谢。

解决方案 »

  1.   

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

  2.   

    procedure TForm32.Edit3KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (key in ['0'..'9','.' ,#8,#13]) then
        key := #0  ;
      if (key = #13) and (trim(edit3.Text) <> '') then
      begin
        if (form32.ComboBox2.ItemIndex = 5) or (form32.ComboBox2.ItemIndex = 6) then
        begin
          Form32.Edit5.SetFocus ;
          Form32.Edit5.SelectAll ;
        end
        else
        begin
          Form32.Edit4.SetFocus ;
          Form32.Edit4.SelectAll ;
        end ;
      end ;
    end;
      

  3.   

    try一下了try
      strtofloat(edit1.text);
    except
      showmessage('输入格式不正确');
    end;
      

  4.   

    谢谢chenzhuo(睡到自然醒) 的指点。结贴了。