發送的數據為0xaa+0x55+調號+頻率1+頻率2+頻率3+(調號+頻率1+頻率2+頻率3和取反)頻率1,2,3是一個長式子的16進制的值的后3個字節大俠幫看下 改好一定追加procedure TForm1.Button1Click(Sender: TObject);vara,b,c,e,f,g:int64;j:string;beginif combobox2.text=''then showmessage('調號為空')elsebeginif combobox3.text=''then showmessage('請選擇頻率')elsebeging:=round(32768*(((4*strtofloat(combobox3.text))/14.7456)-3/2));j:=inttohex(g,6);a:=strtoint(copy(j,1,2));b:=strtoint(copy(j,3,2));c:=strtoint(copy(j,5,2));e:=strtoint(combobox2.text)+a+b+c;f:=(not e);if radiobutton1.Checked thenmscomm1.output:=chr($aa)+chr($55)+chr(strtoint(combobox2.text))+chr(a)+chr(b)+chr(c)+chr(f);Application.CreateForm(Tform5,form5);form5.showmodal;form5.free;end;end;end;combobox2里是 1-20的整數combobox3里是 帶小數點的數為什么會報錯?該怎么改?謝謝 f:=(not e);取反
3 回答

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
''is not a valid integer value 表示你strtoint函數使用的時候有值是'',
從語法上來看看不出來的,要你自己下斷點跟蹤,從
g:=round(32768*(((4*strtofloat(combobox3.text))/14.7456)-3/2));
這句開始下斷點,一步步的走,看值,如果到Application.CreateForm(Tform5,form5);這句還沒有報錯的話,那就不是你這個單元的東西有問題了,就有可能是form5的create事件里有問題代碼。
另外兩點建議:round()這個函數有BUG的,你showmessage(inttostr(round(3.5))) 和showmessage(inttostr(round(4.5))) 看看效果就知道了。一般這樣解決,不保留小數:trunc(a+0.5) 一位小數:trunc((a*10+0.5)/10) 二位小數:trunc((a*100+0.5)/100)
建議你串口發送的數據放一個數組里比較好,象你這個就直接一個整形數組,接收端收到就可以直接用,MSCOMM好像是可以直接發送數組的,久了沒用,忘記了
- 3 回答
- 0 關注
- 272 瀏覽
添加回答
舉報
0/150
提交
取消