|
|
1.1 ! root 1: ! 2: //--------------------------------------------------------------------------- ! 3: ! 4: #include <clx.h> ! 5: #pragma hdrstop ! 6: ! 7: #include "ThreadUnit.h" ! 8: #pragma package(smart_init) ! 9: //--------------------------------------------------------------------------- ! 10: ! 11: // Important: Methods and properties of objects in CLX can only be ! 12: // used in a method called using Synchronize, for example: ! 13: // ! 14: // Synchronize(UpdateCaption); ! 15: // ! 16: // where UpdateCaption could look like: ! 17: // ! 18: // void __fastcall TMyThread::UpdateCaption() ! 19: // { ! 20: // Form1->Caption = "Updated in a thread"; ! 21: // } ! 22: //--------------------------------------------------------------------------- ! 23: ! 24: __fastcall TMyThread::TMyThread(bool CreateSuspended) ! 25: : TThread(CreateSuspended) ! 26: { ! 27: } ! 28: void __fastcall TMyThread::AddToLog() ! 29: { ! 30: Log->Lines->Add(ThreadID); ! 31: } ! 32: //--------------------------------------------------------------------------- ! 33: void __fastcall TMyThread::Execute() ! 34: { ! 35: while(!Terminated) { ! 36: Synchronize(AddToLog); ! 37: /* TThreadList is a simplier way to use a thread-safe TList */ ! 38: CriticalSection->Enter(); ! 39: List->Add(new AnsiString(ThreadID)); ! 40: CriticalSection->Leave(); ! 41: Sleep(1000); ! 42: } ! 43: } ! 44: //---------------------------------------------------------------------------
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.