C++ Builder XE 2 -- 如何在 TEdit 控件中显示变量数据?

标签 c++ c++builder

我希望你们能在这里帮助我。在过去的三周里,我一直在做的是尝试显示 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.0hq3Pˆ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/

相关文章:

c++ - 如何在 RAD Studio XE 中更改 TMsgDlgButtons "Yes"和 "No"按钮的文本?

c++ - 多线程同步

c++ - 如何将 DLL 链接到我的主项目? (获取 Unresolved external 错误)

c++ - 我在 QChartView 中找不到缩放图形的鼠标滚轮滚动事件

c++ - 在 C++ 中重载 "+"orerator 时 that.vect.push_back(0) 和 that.vect.begin() 出错

一个项目中的 C++14 和 C++17

c++ - 包含具有无效位置的 NodeRef 的方式

c++ - 如何向 XCode 5 添加替代编译器

c++ - 如何在 C++ Builder (Clang) 中禁用 RVO?

delphi - 在第二台显示器上启动程序?