来看看程序哪里错了 delphi的

来源:百度知道 编辑:UC知道 时间:2024/09/21 15:41:40
主要是发送一串数据 发送时候老提示''is not a valid integer value

发送的数据为0xaa+0x55+调号+频率1+频率2+频率3+(调号+频率1+频率2+频率3和取反)
频率1,2,3是一个长式子的16进制的值的后3个字节
大侠帮看下 改好一定追加

procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,e,f,g:int64;
j:string;
begin

if combobox2.text=''
then showmessage('调号为空')
else
begin
if combobox3.text=''
then showmessage('请选择频率')
else
begin

g:=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 then
mscomm1.output:=chr($aa)+chr($55)+chr(strtoint(combobox2.text))+chr(a)+chr(b)+chr(c)+chr(f);
Application.CreateForm(Tform5,form5);
form5.showmodal;

''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好像是可以直接发送数组的,久了没用,忘记了

你看看你的 combobox2 里的内容是 数字么, 估计是这抱的错, strtoint(combobox2.text)

f:=(not e);
这个是什么意思?