Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Alternative API of Application->ProcessMessages() for Android and iOS ?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Feb 15, 2017 4:58 PM Last Post By: GAI CHEW KAI
GAI CHEW KAI

Posts: 117
Registered: 7/25/14
Alternative API of Application->ProcessMessages() for Android and iOS ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2017 5:03 PM
Embarcadero® C++Builder XE8 Version 22.0.19027.8951
Android 6.0.1.
Windows 10 Pro x64, 10.0.14393.

The instructions below, switching from __err() to __txt() calls by changing text attributes alignment and its font color,
is not reflected instantly.

void __refresh (void)
{
#if defined( _Windows ) || defined( _WINDOWS ) || defined( _WIN32 ) || defined( _WIN64 )
Application->ProcessMessages();
#endif //#if defined( _Windows ) || defined( _WINDOWS ) || defined( _WIN32 ) || defined( _WIN64 )

}

void TfMain::__err (__in UnicodeString us)
{
// ...lbMsg is TLabel

lbMsg->TextSettings->HorzAlign = TTextAlign::Center;
lbMsg->StyledSettings = lbMsg->StyledSettings >> TStyledSetting::FontColor;
lbMsg->TextSettings->FontColor = TAlphaColor( claOrangered );
lbMsg->TextSettings->Font->Size = 14;
lbMsg->Text = us;
__refresh();
}

void TfMain::__txt (__in UnicodeString us)
{
lbMsg->TextSettings->HorzAlign = TTextAlign::Leading;
lbMsg->StyledSettings = lbMsg->StyledSettings >> TStyledSetting::FontColor;
lbMsg->TextSettings->FontColor = TAlphaColor( claSpringgreen );
lbMsg->TextSettings->Font->Size = 14;
lbMsg->Text = us;
__refresh();
}

What is the alternative API of Application->ProcessMessages() for FMX Android and iOS ?

It seems the messages is not being processed under Android(), sometime until I tapped on certain items next-to it (on the same TPanel) like TComboBox only the lbMsg is reflected.

Please advise.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Alternative API of Application->ProcessMessages() for Android and iOS ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2017 5:19 PM   in response to: GAI CHEW KAI in response to: GAI CHEW KAI
GAI wrote:

#if defined( _Windows ) || defined( _WINDOWS ) || defined( _WIN32 ) ||
defined( _WIN64 )
Application->ProcessMessages();
#endif //#if defined( _Windows ) || defined( _WINDOWS ) || defined( _WIN32
) || defined( _WIN64 )

Checking for _Windows by itself should be enough, as it is defined by all
of the Windows compilers:

#if defined( _Windows )
Application->ProcessMessages();
#endif


But why are you ifdef'ing out non-Windows platforms? ProcessMessages() is
implemented cross-platform.

The real question is, why are you pumping the message queue manually to begin
with? This indicates that you are doing something in the main UI thread
that blocks it from processing messages naturally. Don't do that! This
is especially important on mobile platforms. Never block the main UI thread
- period. If you need to run a lengthy operation, do it in a worker thread
that signals the UI thread of updates when needed.

What is the alternative API of Application->ProcessMessages() for FMX Android
and iOS ?

If all you are interested in is an immediate repaint of the UI, not actually
processing messages, then use the Label's Repaint() method. Definately don't
use ProcessMessages(), not even on Windows, if you can avoid it.

And BTW, if you are going to make multiple changes to a control, you should
wrap the changes with BeginUpdate() and EndUpdate().

Try this:

void TfMain::__err (__in UnicodeString us)
{
    lbMsg->BeginUpdate();
    lbMsg->TextSettings->HorzAlign = TTextAlign::Center;
    lbMsg->StyledSettings = lbMsg->StyledSettings >> TStyledSetting::FontColor;
    lbMsg->TextSettings->FontColor = TAlphaColor( claOrangered );
    lbMsg->TextSettings->Font->Size = 14;
    lbMsg->Text = us;
    lbMsg->EndUpdate();
    lbMsg->Repaint();
}
 
void TfMain::__txt (__in UnicodeString us)
{
    lbMsg->BeginUpdate();
    lbMsg->TextSettings->HorzAlign = TTextAlign::Leading;
    lbMsg->StyledSettings = lbMsg->StyledSettings >> TStyledSetting::FontColor;
    lbMsg->TextSettings->FontColor = TAlphaColor( claSpringgreen );
    lbMsg->TextSettings->Font->Size = 14;
    lbMsg->Text = us;
    lbMsg->EndUpdate();
    lbMsg->Repaint();
}


It seems the messages is not being processed under Android(), sometime
until I tapped on certain items next-to it (on the same TPanel) like
TComboBox only the lbMsg is reflected.

What is your code actually doing at the time __err() and __txt() are being
called?

--
Remy Lebeau (TeamB)
GAI CHEW KAI

Posts: 117
Registered: 7/25/14
Re: Alternative API of Application->ProcessMessages() for Android and iOS ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 14, 2017 5:09 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy,

Apologizing for late reply due to testing your recommended methods yesterday.

>> If all you are interested in is an immediate repaint of the UI, not actually
>> processing messages, then use the Label's Repaint() method.
- Yes, the Repaint() method resolved the instant text message routine issues now.

>> If you need to run a lengthy operation, do it in
>> a worker thread that signals the UI thread of
>> updates when needed.
- Yes, is true indeed, this way helps me to clean up some logic error while displaying instant text.

> What is your code actually doing at the time __err() and __txt() are being
> called?
- ...in a worker thread, receiving TCP packet and process its function,
- ...display messages from the result of the function in red color __err() on error returns and green color __txt() for success.
- ...the logic error is caused by initial __txt() call at UI thread, and second __err() call at worker thread.
- ...if not using Repaint() method, the result of attributes set in __txt() remained for __err(); instead of red color text, it remains as green color.
- for this case, after I created the signaling of text display from worker thread to UI thread, things went fine now.

Thank you very much Remy, I am more confident with Embarcadero C++Builder tools now :)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Alternative API of Application->ProcessMessages() for Android andiOS ? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 14, 2017 7:24 PM   in response to: GAI CHEW KAI in response to: GAI CHEW KAI
GAI wrote:

- ...in a worker thread, receiving TCP packet and process its
function,

- ...display messages from the result of the function in red color
__err() on error returns and green color __txt() for success.

Are you synchronizing with the main UI thread when you call them? It sounds
like maybe no.

- ...the logic error is caused by initial __txt() call at UI thread,
and second __err() call at worker thread.

Since __txt() and __err() touch the UI, they must both be called in the context
of the main UI thread, not in the context of the worker thread.

- ...if not using Repaint() method, the result of attributes set in
__txt() remained for __err(); instead of red color text, it remains as
green color.

You can't update the UI directly in a worker thread, it must sync with the
main UI thread and let the main UI thread do the actual update. Whether
the worker thread waits on the main UI thread to finish that update is up
to you to decide. But for simply status messages, I would not make it wait,
do the update asynchronously, such as with TThread.Queue().

--
Remy Lebeau (TeamB)
GAI CHEW KAI

Posts: 117
Registered: 7/25/14
Re: Alternative API of Application->ProcessMessages() for Android andiOS ? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 15, 2017 4:58 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
> You can't update the UI directly in a worker thread, it must sync with the
> main UI thread and let the main UI thread do the actual update. Whether
> the worker thread waits on the main UI thread to finish that update is up
> to you to decide. But for simply status messages, I would not make it wait,
> do the update asynchronously, such as with TThread.Queue().
- Yes, is true. Great feedbacks, thanks again :)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02