Is thread safe if a thread asynchronously read the information from VCL Controls in Delphi?
eg.
procedure TMyThread.Execute;
var bOK:Boolean;
iOK:Integer;
begin
while not terminated do
begin
bOk:=MyForm.cbCheckBox.Checked;
iOK:=MyForm.Left;
sleep(20);
end;
end;
If it is not thread safe how should I do to catch the event when the checkbox has changed its property.
No it is not safe. Your code is liable to lead to the window handle being created with affinity to the wrong thread.
Don't use the GUI to store your applications state. Use the GUI to show a view onto that state. Once you separate the state from the view you are home and dry. Your worker threads can use the underlying state state without touching GUI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With