Thread-safe in delphi

前端 未结 3 1066
一向
一向 2020-12-03 09:19

I have to modify and change some visual components in a thread and as you know it\'s not safe to doing this.

My question is how to write a completely thread-

3条回答
  •  生来不讨喜
    2020-12-03 09:51

    You should only access VCL objects from main VCL thread.

    Some reading methods (property getters) do work from other threads in practice - but you have to prove it in advance reading VCL sources for the specific Delphi build. Or not use it.

    PS: Synchronize method runs given procedure in main VCL thread, pausing the caller thread, which may lead to a deadlock, if main thread was also blocked.

    Read more: (actually making this answer to list some links)

    • http://www.michael-puff.de/Programmierung/Delphi/Code-Snippets/VCLThreadDemo.shtml
    • http://www.drbob42.com/uk-bug/hood-04.htm
    • http://delphi.about.com/od/kbthread/a/thread-gui.htm
    • Is it better to use TThread's "Synchronize" or use Window Messages for IPC between main and child thread?
    • Delphi 6 : breakpoint triggered on non-VCL thread stops main thread repaints
    • http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devwin32/win32_mthreadusemainthread_xml.html
    • Simplifying VCL thread wrapper code
    • Update a VCL component from CreateAnonymousThread
    • http://thaddy.co.uk/threads/ - the mirror of "Multithreading - The Delphi Way" by Martin Harvey
    • http://otl.17slon.com/ - new Delphi approach to threading

提交回复
热议问题