从串口取数,在receiveData事件中写的代码能正确执行,并且用了try...except,可是在程序运行中还是总弹出一个对话筐说:'' is not a valid float point value。又不影响程序运行,又不能不管。程序中设断也拦不住,不知该怎么办?不知有没有人遇到过?是否程序的bug?  

解决方案 »

  1.   

    应该是你代码的问题,
    可能里面又调用了其它函数,
    如没有,用  StrToFloatDef 这个函数
      

  2.   

    也许aiirii(ari-淘金坑)是对的,我先看看再说
      

  3.   

    procedure TDispFrm.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
    var
      S,tmp,s1:String;
    begin
      try
        SetLength(S, BufferLength); //接收RS232的数据并显示Memo1上。
        Move(Buffer^, PChar(S)^, BufferLength);
        if comm2.CommName<>'COM0' then
            comm2.WriteCommData(PChar(Buffer),BufferLength);
        if pos('=',S)=0 then
            tmp:='0000000'
        else
        begin
            tmp:=copy(s,pos('=',S)+1,7);
            if pos('=',tmp)<>0 then
                    exit;
        end;
        s1:=ReverseString(tmp);
        //showmessage(s1);
      except
        s1:='0000000';
      end;
        iAd.Value:=StrToFloatDef(s1,0)/1000;
    end;
    //这就是相关代码
      

  4.   

    做串口数据处理..建议使用val函数..具体使用参照help
      

  5.   

    用val,小数怎么办?我用StrToFloatDef(s1,0)对话框是不弹了,但总是在实际取到的数和0之间不停的闪烁
      

  6.   

    to solokey:sorry,请问串口会取出小数吗?我觉得应该任何字符都可能取出来
      

  7.   

    COM通讯,发送和接收到的数据都是有协议的..数据段都是规定好的..
    你用 
    function ComStrToDouble(const st:string;var num:doubel):boolean;
    var  i: integer; 
    begin
      val(st,num,i);
      if (i=0) then result:=true
               else  result:=false;
    end;
    这样的方法可以知道接收到的数据是否正常.如果返回false..就证明通讯出了问题.
    另外,具体的数据要根据协议来看了..我见过很多BT的协议...