C++ 生成器 : Refresh FireMonkey Visual Component

标签 c++ c++builder firemonkey

我对 C++ Builder 和 FireMonkey 有疑问。我正在创建一个与 Datasnap Rest WebService 连接的移动应用程序。有些请求有点长,所以我想显示一条等待消息。这是我的代码:

lbl_testConnexion->Text = "Please Wait...";
lbl_testConnexion->TextSettings->FontColor = TAlphaColorRec::Red;
this->Invalidate();

//Call to the Web Service
list<Colis>* l = WS->getListeColis("00DP0097");

lbl_testConnexion->Text = "Success!";

我尝试了 Form->Invalidate() 和 Label->Repaint() 函数,但只显示最后一个文本。 我该怎么做才能在我的函数中动态刷新标签?

最佳答案

文本的更改必须由被请求阻塞的主线程处理。如果您不想为长请求使用单独的线程,则必须调用 Application->ProcessMessages()

lbl_testConnexion->Text = "Please Wait...";
lbl_testConnexion->TextSettings->FontColor = TAlphaColorRec::Red;
Application->ProcessMessages();

//Call to the Web Service
list<Colis>* l = WS->getListeColis("00DP0097");

lbl_testConnexion->Text = "Success!";

注意:

您必须小心使用 Application->ProcessMessages()。您可以在 Internet 上找到许多关于此的文章和讨论。当您使用 VCL 时,存在用于 TWinControl 类型控件的方法 Update,它调用 WinAPI 的函数 UpdateWindow。 Firemonkey 确实有类似的功能,但仅限于 Windows。

包含 FMX.Platform.Win.hpp 并将 Application->ProcessMessages() 替换为 UpdateWindow(Platform::Win::WindowHandleToPlatform(Handle)->Wnd)

关于C++ 生成器 : Refresh FireMonkey Visual Component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38219255/

相关文章:

c++ - 大小为 1 的无效写入,地址 0x... 未堆栈、malloc 或(最近)释放 (Valgrind)

c++ - 创建键值对 Borland C++

listview - 从内存中清除动态 FMX ListView 位图

delphi - FMX 网格与复选框不显示属性

delphi - FMX : Handle of controls

c++ - (Ab)使用构造函数和析构函数进行副作用不好的做法?备择方案?

c++ - 多字符字符常量 [-Wmultichar]

c++ - 在 C++ 中,从 int 到 object 的赋值怎么可能?

delphi - 在 Delphi 中控制 fsMDIChild 窗口的位置

linker - 了解 .cbproj 文件中的包导入