13,825
社区成员
发帖
与我相关
我的任务
分享
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
class TDrawThread: public TThread{
public:
__fastcall TDrawThread()
:TThread(false){;}
void __fastcall Execute(){
do{
Synchronize(draw);
}while(!Terminated);
}
void __fastcall draw(){
static i=0;
Form1->Edit1->Text=i++;
}
};
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClick(TObject *Sender)
{
static TDrawThread *pThread = NULL;
if(pThread == NULL)
{
pThread = new TDrawThread;
}
else
{
pThread->Terminate();
pThread->WaitFor();
delete pThread;
pThread = NULL;
}
}
//---------------------------------------------------------------------------