It may be easier to simply defer your logic until the OnShow
event OnShow
, without using a thread at all. For instance:
const UINT WM_DO_WORK = WM_USER + 1; void __fastcall TForm1::FormShow(TObject *Sender) { PostMessage(Handle, WM_DO_WORK, 0, 0); } void __fastcall TForm1::WndProc(TMessage &Message) { if (Message.Msg == WM_DO_WORK) {
If you really want to use the code, you can do it like this:
class TMyThread : public TThread { protected: virtual void __fastcall Execute(); public: __fastcall TMyThread(); }; __fastcall TMyThread::TMyThread() : TThread(true) { FreeOnTerminate = true;
source share