Delphi Tip – FMX Update a progress bar within work loop.

DX_Logo_256x256px

Your application must do some work which blocks the main thread, and your progress indicator does not update until the job is done. Under windows you might have introduced “Application.ProcessMessages()” but this is not cross platform and can cause serious performance problems under FMX. What can you do about it?

This is precisely the question one of my customers posed to me recently. His application would poll a port within a while loop, and update a progress bar. My suggestion was that he use the threading library to move the polling work into a separate thread, and I wrote the attached sample application to demonstrate.

Unfortunately, in this customers case the port is tied to the main thread also, so this solution didn’t work for him, we’re exploring alternative options. I decided however that this sample might be useful for others without the single-thread constraint, and wanted to share it with you here…

Download the sample: here

Facebooktwitterredditpinterestlinkedintumblrmail

3 thoughts on “Delphi Tip – FMX Update a progress bar within work loop.”

  1. Since writing this work-around on my blog, I’ve encountered the blocking thread issue again and adjusted the code. A better strategy is to place your work within the TTask, and then call TThread.Synchronize() to update the UI. I used this technique in my video series “Brutally Roll Your Own Backend – Part 8” which can be found here http://chapmanworld.com/2016/07/14/brutally-roll-your-own-backend-part-8/ (skip to around 42-43 minutes in).

Leave a Comment