用Edit1获得float型数据,如果用户在Edit1里输入了字符,程序运行错误。
为避免用户输入错误导致程序运行出错,如何检验Edit1里的内容是不是float型?
谢谢!

解决方案 »

  1.   

    //验证是否是float型数据
    try
      StrToFloat(Edit1.text);
    except
      application.messagebox('输入错误','提示',64);
      Exit;
    end;
    //验证是否是整型数据
    try
      StrToInt(Edit1.text);
    except
      application.messagebox('输入错误','提示',64);
      Exit;
    end;
      

  2.   

    在Edit1的OnKeyPress事件中
    begin
      if not (key in ['0'..'9','.',#8,#13]) then
        begin
          Beep;
          key:=#0;   
        end;
    end;
      

  3.   

    onedit1.keypress()
     begin   if not(key in ['0,..'9','.','-',#8,#13]) then
         key:=#0;
      end;