多线程怎么用呀

park1974 2003-02-21 09:52:04
我建立了一个unit1之后又建立了一个线程unit2,我想在unit1的按扭click事件中调用线程unit2,可是总是不行,即使我在unit1里加上了#include "Unit2"这个语句也不行。
到底应该怎么调用线程呢?
...全文
63 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
牧牛人软件 2003-02-21
  • 打赏
  • 举报
回复
unit1:

void __fastcall TCleanForm::Button1Click(TObject *Sender)
{

TCleanDataThread * CleanDataThread;
if(Application->MessageBox("请确认是否要清理数据!!", "确认", MB_OKCANCEL) != IDOK) return;
CleanDataThread = new TCleanDataThread(sDate);
CleanDataThread->Priority = tpIdle;
}




unit2:
//---------------------------------------------------------------------------

#ifndef CleanDataThreadH
#define CleanDataThreadH
//---------------------------------------------------------------------------
#include <Classes.hpp>
//---------------------------------------------------------------------------
class TCleanDataThread : public TThread
{
private:
// void __fastcall CleanData();
protected:
void __fastcall Execute();
void __fastcall CleanData();
public:

__fastcall TCleanDataThread(AnsiString sdate);

};
//---------------------------------------------------------------------------
#endif



*.cpp


//---------------------------------------------------------------------------

#include <vcl.h>
#include <stdio.h>
#pragma hdrstop
#include "TranHistory.h"
#include "CleanDataThread.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 Unit1::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------

__fastcall TCleanDataThread::TCleanDataThread(AnsiString sdate)
: TThread(false)
{
}

void __fastcall TCleanDataThread::CleanData()
{

try{


CleanForm->ADOStoredProc1->Parameters->Items[1]->Value=CleanForm->DateTimePicker1->Date.FormatString("yyyy-mm-dd");
// CleanForm->ADOStoredProc1->Prepare();
CleanForm->ADOStoredProc1->ExecProc();
CleanForm->num=CleanForm->ADOStoredProc1->Parameters->Items[0]->Value;

}
catch (Exception &exception)
{
Application->ShowException(&exception);

}


}

//---------------------------------------------------------------------------
void __fastcall TCleanDataThread::Execute()
{
CleanData();
//---- Place thread code here ----
}
//------------------------------------------
playguy 2003-02-21
  • 打赏
  • 举报
回复
线程是对象,要创建后才能使用的。

欢迎访问小弟的网站:
http://www.aslike.net
牧牛人软件 2003-02-21
  • 打赏
  • 举报
回复
你不太揭贴啊!

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧