What conditions I should met to call TForm's members from win32 thread?
I created a thread using CreateThread() with standard function prototype
DWORD WINAPI func(LPVOID param);
When I call TForm's members sometimes it crashes with access 开发者_开发知识库violation. I do not want use Embarcadero's TThread style functions, prefer to win32 std api. What synchronize/other conditions I should met to successfully call TForm's or its descendants members?
Thanks
Calling VCL methods in threads other than the main thread is not supported.
You need to find a way to keep all your VCL access in the main thread. One commonly used technique is the Synchronize()
method. You could also send windows messages since they will always be marshalled across to the thread that owns the window.
I imagine that it's the same in C++ Builder as it is in Delphi, but in Delphi it is preferable to call BeginThread()
rather than CreateThread()
. BeginThread()
is a lightweight wrapper of CreateThread()
but the main thing it does for you is to set the IsMultiThread
global variable. If you do insist on calling CreateThread()
then you must set IsMultiThread
true first.
精彩评论