mscomm发送时Range check error!,再运行就overflow convert shortint to btye
int file_longth;
int i,n;
char send_data[512];//定义发送数据
send_data[0] = 0; //file_longth允许最大长度为24位
send_data[1] = (char)((file_longth>>16)&0xff);
send_data[2] = (char)((file_longth>>8)&0xff);
send_data[3] = (char)(file_longth&0xff);
for(i=4;i<512;i++)
send_data[i] = 0;
OleVariant Tx_Rx_Buffer;
n=512;
Tx_Rx_Buffer=VarArrayCreate(OPENARRAY(int,(0,n-1)),varByte);
for(i=0;i<n;i++)
{
Tx_Rx_Buffer.PutElement(send_data[i],i);
}
可是我运行的时候到这里就出错,提示我“raised exception class ERangeError with message 'Range check error'. Process stopped. Use Step or Run to continue.”然后我就点运行往下走,可是又提示我“raised exception class EVariantOverflowError with message 'Overflow while converting variant of type (ShortInt) into type (Byte)'. Process stopped. Use Step or Run to continue.”
我把那几句给send_data[1]、send_data[2]、send_data[3]赋值的语句去掉之后就没有问题了。看来问题肯定出在这几句上面,可是我用SIZEOF方法测试是1字节呀,不知怎么会溢出错误!期待热心人指点下。
我搜了一下咱们网站的帖子,发现以前有人提出过这个问题,
http://topic.csdn.net/t/20060325/09/4638942.html
那位提问题的楼主自己把问题解决了,可是那位仁兄没有说解决办法。
现在谁帮帮我!十分感谢!