我的系統 中用至strtofloat(edit1.text)函數,但當edit1的內容為空時,報錯(is no a vialid floating point value),請高手指點怎 樣解決此問題,問題解決,馬上給分

解决方案 »

  1.   

    将StrToFloat的源代码复制一份出来,修改判断部分,删除抛出异常的代码即可。
    说着复杂,一看代码就明白了。
      

  2.   

    try 
    r:=strtofloat(edit1.text);
    except
    end;
      

  3.   

    if edit1.Text <>'' then
      StrToFloat(edit1.text);
      

  4.   

    其实就是进行一个判断而已, yq3woaini(哈哈镜(初级代码工)(★★★)) 是判断后处理, ly_liuyang(Liu Yang) 是抛出异常自己提示。
    都可以的 呵呵 :)
      

  5.   

    还是觉得用
    if edit1.Text <>'' then
      StrToFloat(edit1.text);
    简单
      

  6.   

    try
    a:=StrToFloat(Edit1.Text)
    except
    showmessage('无效');
    end;
      

  7.   

    我的語句是self.adoquery1.asfloat:=strtofloat(self.edit.text),但是我要求隻能輸入數字和點,並要保留4位小數,值可以為空。請寫出詳細的語句
      

  8.   

    self.adoquery1.asfloat:=strtofloat(self.edit.text)self.adoquery1.FieldByName('').asfloat:=strtofloat(self.edit.text);
      

  9.   

    edit1的KeyPress事件if not (key in ['0'..'9','.',#8]) then key := #0;其他上面都说了吧^_^
      

  10.   

    用 StrToFloatDef(Edit1.Text,0);表示如果Edit.Text不能转换为Float的话,返回一个默认值.....这种会避免你的转换错误 但可能数据会达不到你的要求
      

  11.   

    我想問一下  key:=#10 是什麼意思 ?
    另外反過來用self.edit1.text:=floattostr(self.adoquery1.filedsbyname('dosage').asfloat)同樣也有錯,提示字段值不能為空,怎樣解決,
    maskedit 怎樣設置顯示在沒4位小數是自動補齊。
      

  12.   

    try
    v:=StrToFloat(Edit1.Text)
    except
    else
    showmessage('invalid value!);
    end;
      

  13.   

    try
      temp:=StrToFloat(Edit1.Text);
    except
      temp:=StrToFloat('0.0');
    end;
      

  14.   

    if trim(Edit1.Text)<>'' then v:=StrToFloat(Edit1.Text)
      

  15.   

    写过变相StrToFloat
    function P_StrToFloat(Str:String):Real;
    begin
      if Trim(Str)<>'' then Result:=StrToFloat(Str)
      else Result:=0;
    end;
    然后调用它就不会出现这种情况了
      

  16.   

    我要求如果eidt 的值為空,轉換後也必須為空
      

  17.   

    将strtofloat(edit1.text)改成strtofloatdef(edit1.text,0)就可以了
      

  18.   

    adoquery1.FieldByName('FF').asSTRING:=edit.text;
      

  19.   

    你要判断你的edit1.text的字是否合法啊。
    try 
    r:=strtofloat(edit1.text);
    except
    end;或者if trim(Edit1.Text)<>'' then v:=StrToFloat(Edit1.Text)