12      //输入12
12.1    //输入12.1
12.12   //输入12.12
12.121  //输入12.12

解决方案 »

  1.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    var
      s: string;
      i: integer;
    begin
      s:= edit1.Text;
      for i:= 0 to length(s)-1 do
      begin
        if s[i] = '.' then
        begin
          if length(s)-i >1 then key:= #0;
        end;
      end;
    end;
      

  2.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    var
      s: string;
      i,j: integer;
    begin
      s:= edit1.Text;
      i:=pos('.',s);
      j:=Length(s);
      if j-i>=2 then 
        key:= #0;
    end;
      

  3.   

    首先限定edit输入字符是数字,然后能过将string转换为数字型,再使用数学函数求得小数个数进行叛定即可!
      

  4.   

    procedure MyKeyPress(MyKess: TEdit; Len: integer; var Key: char);
    begin
       if MyKess.SelLength =length(MyKess.Text) then
          MyKess.Clear;
      if (Key <> '1') and (Key <> '2') and (Key <> '3') and (Key <> '4') and (Key <>
        '5') and (Key <> '6') and (Key <> '7') and (Key <> '8') and (Key <> '9') and
        (Key <> '0') and (Key <> '.') and (Key <> '-') then
        begin
          if Key <> #8 then
            Key := char(0);
        end
      else
        begin
          if Key = '.' then
            begin
              if pos('.', MyKess.Text) <> 0 then
                Key := char(0)
            end
          else
            if Key = '-' then
              begin
                if trim(MyKess.Text)<>'' then
                  Key := char(0)
              end
          else
            begin
              if (pos('.', MyKess.Text) <> 0) and (Length(copy(MyKess.Text, pos('.',
                MyKess.Text) + 1, Length(MyKess.Text))) > Len - 1) then
                Key := char(0)
              else
                //if Key='0' then
                  begin
                    if (trim(MyKess.text)='0') or (trim(MyKess.text)='-0') then
                      Key := char(0)
                  end;
            end;
        end;
    end;这个函数能满足你
    EditKeyPress事件中:MyKeyPress(edit1,2, Key);
      

  5.   

    用 maskedit解决
    正则表达式
      

  6.   

    if (Key <> '1') and (Key <> '2') and (Key <> '3') and (Key <> '4') and (Key <>
        '5') and (Key <> '6') and (Key <> '7') and (Key <> '8') and (Key <> '9') and
        (Key <> '0') and (Key <> '.') and (Key <> '-') 眼花,用in不好吗?呵呵