c++ builder中字符型转为十六进制数显示时出现说“是个无效的整型值”,求各位帮小弟解答。

我的部分程序如下:
double temp1=0,temp2=0,temp3=0,temp4=0,temp5=0,temp6=0,temp7=0,temp8=0,temp9=0,temp10=0,temp11=0,temp12=0,temp13=0,temp14=0,temp15=0,temp16=0,temp17=0,temp18=0,temp19=0;
OleVariant s;//声明一个用于接收数据的OleVariant变量。
if(MSComm1->CommEvent==comEvReceive)// 接收缓冲区中是否收到Rthreshold个字符。
{
if(MSComm1->InBufferCount) //是否有字符驻留在接收缓冲区等待被取出
{
s=MSComm1->Input;//接收数据
str=s.AsType(varString);//把接收到的OleVariant变量转换成AnsiString类型
str1=str.SubString(1,2);
str2=str.SubString(3,2);
str3=str.SubString(5,2);
str4=str.SubString(7,2);
str5=str.SubString(9,2);
str6=str.SubString(11,2);
str7=str.SubString(13,2);
str8=str.SubString(15,2);
str9=str.SubString(17,2);
str10=str.SubString(19,2);
str11=str.SubString(21,2);
str12=str.SubString(23,2);
str13=str.SubString(25,2);
str14=str.SubString(27,2);
str15=str.SubString(29,2);
str16=str.SubString(31,2);
str17=str.SubString(33,2);
str18=str.SubString(35,2);
str19=str.SubString(37,2);

str1="0x"+str1;
str2="0x"+str2;
str3="0x"+str3;
str4="0x"+str4;
str5="0x"+str5;
str6="0x"+str6;
str7="0x"+str7;
str8="0x"+str8;
str9="0x"+str9;
str10="0x"+str10;
str11="0x"+str11;
str12="0x"+str12;
str13="0x"+str13;
str14="0x"+str14;
str15="0x"+str15;
str16="0x"+str16;
str17="0x"+str17;
str18="0x"+str18;
str19="0x"+str19;

temp1=StrToInt(str1);
temp2=StrToInt(str2);
temp3=StrToInt(str3);
temp4=StrToInt(str4);
temp5=StrToInt(str5);
temp6=StrToInt(str6);
temp7=StrToInt(str7);
temp8=StrToInt(str8);
temp9=StrToInt(str9);
temp10=StrToInt(str10);
temp11=StrToInt(str11);
temp12=StrToInt(str12);
temp13=StrToInt(str13);
temp14=StrToInt(str14);
temp15=StrToInt(str15);
temp16=StrToInt(str16);
temp17=StrToInt(str17);
temp18=StrToInt(str18);
temp19=StrToInt(str19);

Memo1->Text=Memo1->Text+temp1;
Memo2->Text=Memo2->Text+temp2;
Memo3->Text=Memo3->Text+temp3;
Memo4->Text=Memo4->Text+temp4;
Memo5->Text=Memo5->Text+temp5;
Memo6->Text=Memo6->Text+temp6;
Memo7->Text=Memo7->Text+temp7;
Memo8->Text=Memo8->Text+temp8;
Memo9->Text=Memo9->Text+temp9;
Memo10->Text=Memo10->Text+temp10;
Memo11->Text=Memo11->Text+temp11;
Memo12->Text=Memo12->Text+temp12;
Memo13->Text=Memo13->Text+temp13;
Memo14->Text=Memo14->Text+temp14;
Memo15->Text=Memo15->Text+temp15;
Memo16->Text=Memo16->Text+temp16;
Memo17->Text=Memo17->Text+temp17;
Memo18->Text=Memo18->Text+temp18;
Memo19->Text=Memo19->Text+temp19;

str1="0x"+str1; 不要。

temp1=StrToInt(str1); 改为
=>

{long n; sscanf(str1.c_str(), "%X", &n); temp1=n;}

为何不用数组和循环?不累吗。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-11-09
str1="0x"+str1;
temp19=StrToInt(str19);
这个东西不需要了!
直接用函数Memo1->Text=Memo1->Text+"0x"+IntToHex(str1,2);追问

还是提示:[C++ Error] Unit1.cpp(162): E2285 Could not find a match for 'IntToHex(AnsiString,int)'

追答

Memo1->Text=Memo1->Text+"0x"+IntToHex(StrToInt(str1),2);
改成这样呢!