问题
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