This is a bit tricky. Here's a simple example:
Delphi-Quellcode:
Type
TMythread =
Class (TThread)
private
fLabelMsg :
String;
// a private field to display in the main form from within a thread
procedure DoShowMessage;
Protected
Procedure Execute;
Override;
End;
Procedure TMyThread.DoShowMessage;
Begin
MainForm.MyLabel.Caption := fLabelMsg;
End;
Procedure TMyThread.Execute;
Begin
....
fLabelMsg :='
Show this!';
// Write what you want to display in your private fields
Synchronize (DoShowMessage);
// Call the method which actually talks to the VCL via Synchronize
...
// The Thread terminates automatically, when the Execute-Method is exited.
End;
Bear in mind that ANY
access to
VCL-Controls (not only on the main form) must be wrapped in a Synchronize call, otherwise your app will hang.