Can I read VCL control properties in a non-GUI thread?

Is a thread safe if a thread asynchronously reads 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 to do this in order to catch an event when the checkbox changed its property.

+6
source share
1 answer

No, this is not safe. Your code may cause the window handle to be created with reference to the wrong topic.

Do not use the graphical interface to store the state of your applications. Use the graphical interface to display the view in this state. Once you separate the state from the species, you are at home and dry. Your workflows can use the ground state without touching the graphical interface.

+10
source

All Articles