Unit3.cpp
上传用户:gyjjlc
上传日期:2013-03-29
资源大小:2124k
文件大小:1k
源码类别:

多显示器编程

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit3.h"
  5. #include "Unit1.h"
  6. #pragma package(smart_init)
  7. //---------------------------------------------------------------------------
  8. //   Important: Methods and properties of objects in VCL can only be
  9. //   used in a method called using Synchronize, for example:
  10. //
  11. //      Synchronize(UpdateCaption);
  12. //
  13. //   where UpdateCaption could look like:
  14. //
  15. //      void __fastcall Unit3::UpdateCaption()
  16. //      {
  17. //        Form1->Caption = "Updated in a thread";
  18. //      }
  19. //---------------------------------------------------------------------------
  20. __fastcall TDisplayThread::TDisplayThread(bool CreateSuspended)
  21.     : TThread(CreateSuspended)
  22. {
  23.     FreeOnTerminate=true;
  24.     Resume();
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TDisplayThread::Execute()
  28. {
  29.     while(!Terminated)
  30.     {
  31.         //标注临界区头
  32.         TQ->Acquire();
  33.         //访问VCL必须用同步方法
  34.         Synchronize(ListInMemo);
  35.         //标注临界区尾
  36.         TQ->Release();
  37.     }
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall TDisplayThread::ListInMemo(void)
  41. {
  42.     //因容量有限,超过50行时,删除首行
  43.     if(Form1->Memo1->Lines->Count>50)
  44.         Form1->Memo1->Lines->Delete(0);
  45.     //添加新行
  46.     Form1->Memo1->Lines->Add(AnsiString(Form1->LetterTable,26));
  47. }