Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Updating a label


This question is answered.


Permlink Replies: 5 - Last Post: Dec 19, 2015 8:35 AM Last Post By: Markus Humm
Markus Humm

Posts: 5,113
Registered: 11/9/03
Updating a label  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 17, 2015 5:56 AM
Hello,

using D10 Seattle for writing a FMX Android app I have some problem getting a label and a progressbar updated.

The app does something from within a OnTimer event and in that it also calls some event of mine which then
changes the text and the value of my label and my progressbar. So the timer runs until all data has been processed,
means it is being called in quick succession.

Just these screen updates never make it to the screen. If I make the timer interval longer the screen gets updated,
but that can't be the solution in the end. If I insert application.processmessages for testing purposes the screen
gets updated as well but after the app finishes this task the app is somehow just being terminated without me
wanting this. Using refresh or some form of invalidate followed by refresh didn't help either.

If I use
TThread.Synchronize(nil, 
                               procedure
                               begin
                                  MyLabel.Text := x.ToString + '% done';
                                  MyProgressBar.Value := x;
                               end);


it doesn't help. The text and progressbar aren't updated.

Any hints what I could try to overcome this issue?

Greetings

Markus
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Updating a label  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 17, 2015 7:38 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:
Hello,

using D10 Seattle for writing a FMX Android app I have some problem getting a label and a progressbar updated.

The app does something from within a OnTimer event and in that it also calls some event of mine which then
changes the text and the value of my label and my progressbar. So the timer runs until all data has been processed,
means it is being called in quick succession.

Just these screen updates never make it to the screen. If I make the timer interval longer the screen gets updated,
but that can't be the solution in the end. If I insert application.processmessages for testing purposes the screen
gets updated as well but after the app finishes this task the app is somehow just being terminated without me
wanting this. Using refresh or some form of invalidate followed by refresh didn't help either.

If I use
TThread.Synchronize(nil, 
                               procedure
                               begin
                                  MyLabel.Text := x.ToString + '% done';
                                  MyProgressBar.Value := x;
                               end);


it doesn't help. The text and progressbar aren't updated.

Any hints what I could try to overcome this issue?

Greetings

Markus

Hello,

would it be a viable solution to pack the operation I want to display the progress of into a thread and from that one call the progress event via synchronize? Would that lead to a "unblocked" main/gui thread and that when calling synchronize that the main gui thread really does these screen updates or would really frequent calls to synchronize lead again to the GUI not repainting because it thinks that the next change will come soon anyway?

Greetings

Markus
Gilbert Padilla

Posts: 315
Registered: 3/8/04
Re: Updating a label  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 17, 2015 9:51 AM   in response to: Markus Humm in response to: Markus Humm
I think TStopWatch may serve you better than the TTimer component.
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Updating a label  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 17, 2015 11:51 AM   in response to: Gilbert Padilla in response to: Gilbert Padilla
Am 17.12.2015 um 18:51 schrieb Gilbert Padilla:
I think TStopWatch may serve you better than the TTimer component.

What for? TStopWatch is for meassuring the time. But that's not my
issue. My issue seems to be some "overloading" of the main application
thread so it doesn't do any repaints of the screen.

Greetings

Markus
Gilbert Padilla

Posts: 315
Registered: 3/8/04
Re: Updating a label
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2015 8:33 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Updating a label  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 19, 2015 8:35 AM   in response to: Gilbert Padilla in response to: Gilbert Padilla
Am 19.12.2015 um 05:33 schrieb Gilbert Padilla:

Hello,

thanks for the link.
I did change my code to use a thread just yesterday and now it works
like a charm. The new overloads for Synchronize taking an anonymous
method as parameter were quite usefull as well.

Finally a case where I thought annon methods to be usefull ;-)

Greetings

Markus
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02