Unit2.cpp
资源名称:第6章 多线程编程.rar [点击查看]
上传用户:gyjjlc
上传日期:2013-03-29
资源大小:2124k
文件大小:1k
源码类别:
多显示器编程
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit2.h"
- #include "Unit1.h"
- #pragma package(smart_init)
- //---------------------------------------------------------------------------
- // Important: Methods and properties of objects in VCL can only be
- // used in a method called using Synchronize, for example:
- //
- // Synchronize(UpdateCaption);
- //
- // where UpdateCaption could look like:
- //
- // void __fastcall Unit2::UpdateCaption()
- // {
- // Form1->Caption = "Updated in a thread";
- // }
- //---------------------------------------------------------------------------
- __fastcall TReverseThread::TReverseThread(bool CreateSuspended)
- : TThread(true)
- {
- FreeOnTerminate=true;
- Resume();
- }
- //---------------------------------------------------------------------------
- void __fastcall TReverseThread::Execute()
- {
- while(!Terminated)
- {
- //等待信号事件处于信号态,一旦等到事件处于信号态随即复位至无信号态
- if(Form1->pEvent->WaitFor(10)==wrSignaled)
- {
- //字母表顺序、逆序交替排序
- for(int i=0;i<26;i++)
- Form1->LetterTable[i]='Z'+'A'-Form1->LetterTable[i];
- }
- //设置事件处于信号态
- Form1->pEvent->SetEvent();
- }
- }
- //---------------------------------------------------------------------------
English
