Firemonkey iPad waiting icon

雨燕双飞 提交于 2019-12-11 18:12:44

问题


I've got two tabs on my application. Both of them have a table - one for input and one for output. When the tab for the output table is activated, a process is triggered which analyze the data and populated the output grid.

The output grid takes a few seconds to render and I would like to display some animated icon. I have tried a TImage with a TFloat animation as well as the TAniIndicator. Both of them seems to freeze while the analyze process is running.


回答1:


Sounds like you have single-threaded application. The problem is that one thread can do one "task" at a time.

In the case of single-threaded applications the main thread is responsible for a couple of things:

  • process UI stuff (refreshing, drawing etc.)
  • execute your code i.e. react on control's events like TabXActivate()
  • etc.

So when you execute your Analyze() function the main thread is blocked and thus cannot refresh UI. As a side effect Animations seem to freeze.

I would suggest moving long-running tasks in separate threads. After the task has finished signal the main thread to stop the indicator and continue to receive user input. This way the main IU thread will not be blocked and TAniIndicator will function correctly.

NB: Beware of thread synchronization and thread safety! VCL/FMX components ARE NOT thread-safe. You can find useful information here:

  • Synchronizing Threads and GUI in Delphi application
  • Under The Hood #4 - Is the VCL thread-safe?
  • INDY 10 TCP Server - Combine with non thread safe VCL Code
  • Multithreading - The Delphi Way


来源:https://stackoverflow.com/questions/18914314/firemonkey-ipad-waiting-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!