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?

 

[ Continue Reading ]

Anonymous
  • 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 chapmanworld.com/.../ (skip to around 42-43 minutes in).
  • Drat, the blog cut off my code because it contained a less than sign. Let's try this: procedure TForm23.RunInITask(Sender: TObject); var incTask:ITask; begin ProgressBar1.Value:=0; incTask:=TTask.create(IncrementBar); incTask.Start; incTask.Wait(); while not (ProgressBar1.Value = 100.0) do Sleep(10); end;
  • My earlier post seems to have been cut off. The code was: procedure TForm23.RunInITask(Sender: TObject); var incTask:ITask; begin ProgressBar1.Value:=0; incTask:=TTask.create(IncrementBar); incTask.Start; incTask.Wait(); while ProgressBar1.Value
  • This is problem I reported WAY back in 2013 and it has received something like 83 up votes since then (qc.embarcadero.com/.../qcmain.aspx and has yet to be addressed. So unfortunately, this is hardly a new issue and the fact that something so fundamental has remained unresolved is incredibly frustrating. In any case, call me stupid but why does this workaround actually work? Even though this is running in a separate thread you are running a very tight loop and if it won't update with the main thread, why is it updating in this thread. Also, this updating is extremely fragile. If I try to do some other processing while this thread is running, for example, it doesn't update at all. To wit, if I launch this updating task and then continue to do any work, INCLUDING just waiting for it to finish, it never updates at all. var incTask:ITask; begin incTask:=TTask.create(IncrementBar); incTask.Start; while ProgressBar1.Value