SetEditOnePoint() 使Edit控件中只能输入数字和1个小数点


{使Edit控件中只能输入数字和1个小数点 }
// 调用 放在Edit的KeyPress事件下 setOnePoint(Key,Edit1);
procedure SetEditOnePoint(var Key: Char;CTRL:Tedit);
var p:integer; tp:TPoint;
begin
   if key in['0'..'9','+','-','.'] then
      begin
         if key in['+','-'] then
             begin
               p:=pos('+',CTRL.Text)+pos('-',CTRL.Text);
               if p>0 then
                  key:=#0
               else
                  begin
                     GetCaretPos(tp);
                     if tp.x>1 then key:=#0;
                  end;
             end
         else  if key='.' Then
             begin
                p:=pos('.',CTRL.Text);
                if p>0 then key:=#0;
             end;
      end
   else if key>#31 then key:=#0;
end;




你可能感兴趣的:(只能输入数字)