我希望你们能在这里帮助我。在过去的三周里,我一直在做的是尝试显示 3 个变量的内容(1 个字符变量相应地包含“-”或“+”符号,另外两个整数变量包含温度测量值)我正在尝试执行 id 在 TEdit 控件中显示这些变量的内容,例如: + 26.3 。就这么简单。
我尝试了几种功能但没有成功,让我向您展示:
(其中 temp_txtBox_Cond 是 TEdit 控件的名称)
temp_txtBox_Cond->Text=(L"%c %i. %i",temp_sign,temp_temp_int,temp_temp_dec,test_buf,n);
temp_txtBox_Cond->Text.printf(L"%c %i. %i",temp_sign,temp_temp_int,temp_temp_dec);
sprintf(test_buf,"%c %i.%i",temp_sign,temp_temp_int,temp_temp_dec);
temp_txtBox_Cond ->Text.sprintf(L"%c %i.%i",temp_sign,temp_temp_int,temp_temp_dec,test_buf);
temp_txtBox_Cond->Text=("%c %i. %i",temp_sign,temp_temp_int,temp_temp_dec);
temp_txtBox_Cond->Text = AnsiString(temp_sign,temp_temp_int,temp_temp_dec);
temp_txtBox_Cond->Text = (AnsiString(temp_sign)+AnsiString(temp_temp_int)+AnsiString (temp_temp_dec));
String s(temp_sign);
String d(temp_temp_dec);
String i(temp_temp_int);
temp_txtBox_Cond->Text = s+" "+i+"."+d;
没有成功。这非常令人沮丧。
请大家需要你的帮助。提前致谢。
嗯,这有点奇怪,因为对于上述大多数功能,我得到的是 0
、+0.0
或 hq3Pˆ15PPhå
(这听起来像是内存问题)。让我告诉你:
与:
temp_txtBox_Cond->Text = (L"%c %i.%i",temp_sign,temp_temp_int,temp_temp_dec,test_buf);
我得到:hq3Pˆ15PPhå
与:
temp_txtBox_Cond->Text.printf(L"%c %i. %i",temp_sign,temp_temp_int,temp_temp_dec);
我知道文本框是空白的
与:
sprintf(test_buf,"%d. %d",temp_temp_int,temp_temp_dec);
temp_txtBox_Cond->Text =(test_buf,"%c %d. %d",temp_sign,temp_temp_int,temp_temp_dec);`
我得到 0。
与:
temp_txtBox_Cond->Text =("%c %d. %d",temp_sign,temp_temp_int,temp_temp_dec);`
我也得到 0。
并与:
temp_txtBox_Cond->Text = AnsiString(temp_sign,temp_temp_int,temp_temp_dec): I got +0.0
这些是错误。
嗨,雷米,
当然没问题。这是我用来获取 temp_sig、temp_temp_int 和 temp_temp_dec 的代码:
WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
ikor_msg_id = ikor_id_bld (app_priority, zone, dest_UCP, 0x20, 0x03);
wait_for_msg(h, 0x5200, 500, data);
if (data[0] == 1)
{
temp_sign = '+';
}
else if (data[0] == 0)
{
temp_sign = '-';
}
else
{
temp_sign = '?';
}
temp_temp_int = data[1];
temp_temp_int <<= 8;
temp_temp_int += data[2];
temp_temp_dec = temp_temp_int;
temp_temp_int /= 10;
temp_temp_dec -= (temp_temp_int * 10);
}
这里我试图显示数据:
void __fastcall TForm1::temp_txtBox_CondChange(TObject *Sender )
{
unsigned long ikor_msg_id = 0;
long ikor_id_bld( long p_temp, long z_temp, long d_temp, int m_temp, int s_temp);
int wait_for_msg(CANHANDLE handle,int id,int timeout,unsigned char *data);
CANHANDLE h;
unsigned char data [8];
/***Here is where i tried all the attempts that I posted ****/
}
以及我在 header 中声明的变量:
#ifndef __Variables_Cond__
#define __Variables_Cond__
#ifdef __cplusplus
extern "C" {
#endif
unsigned int temp_temp_int;
unsigned int temp_temp_dec;
unsigned char temp_sign;
#ifdef __cplusplus
} #endif
#endif
最佳答案
我建议如下:
TCHAR temp_buf[256];
wsprintf(temp_buf, _T("%c %d.%d"), temp_sign, temp_temp_int, temp_temp_dec);
temp_txtBox_Cond->Text = temp_buf;
关于C++ Builder XE 2 -- 如何在 TEdit 控件中显示变量数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11188524/