C++ Builder: Refresh FireMonkey Visual Component

我怕爱的太早我们不能终老 提交于 2019-12-11 07:32:57

问题


I have a problem with C++ Builder and FireMonkey. I am creating a mobile application connected with a Datasnap Rest WebService. Some requests are a little bit long so I want to display a waiting message. Here is my code:

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!";

I tried functions Form->Invalidate() and Label->Repaint() but only the last text is displayed. What can I do to dynamically refresh the Label in my function?


回答1:


The change of the text has to be handled by the main thread which is blocked by the request. If you don't want to use a seperate thread for long requests you have to call 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!";

Note:

You have to be carefull with Application->ProcessMessages(). You can find many articles and discussions about this in the internet. When you work with the VCL there exists the method Update for controls of Type TWinControl which calls the function UpdateWindow of the WinAPI. Firemonkey does have a similar function, but only for Windows.

Include FMX.Platform.Win.hpp and replace Application->ProcessMessages() with UpdateWindow(Platform::Win::WindowHandleToPlatform(Handle)->Wnd)



来源:https://stackoverflow.com/questions/38219255/c-builder-refresh-firemonkey-visual-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!