线程的析构函数为什么不执行

lyyanzi 2011-01-11 05:01:59
__fastcall CCLTP::CCLTP(bool CreateSuspended,AnsiString FileName,int Method)
: TThread(CreateSuspended)
{
this->FileName=FileName;
this->Method=Method;
this->strFileName=ExtractFileName(FileName);
this->strFilePath=ExtractFilePath(FileName);
aFileName="";
bFileName="";
g_pCLInfo=new CLInfo;
TMultiReadExclusiveWriteSynchronizer *section=new TMultiReadExclusiveWriteSynchronizer();
section->BeginWrite();
CLInfoCount++;
section->EndWrite();
delete section;
g_pCLInfo->HPHM="-" ;
g_pCLInfo->HPZL="" ;
g_pCLInfo->HPYS="无" ;
g_pCLInfo->WFXW="" ;
g_pCLInfo->DYCD="";
g_pCLInfo->XHDZT="-" ;
g_pCLInfo->SRSC="-" ;
g_pCLInfo->SFWZ="-";
}
__fastcall CCLTP::~CCLTP()
{
delete g_pCLInfo;
TMultiReadExclusiveWriteSynchronizer *section=new TMultiReadExclusiveWriteSynchronizer();
section->BeginWrite();
CLInfoCount--;
section->EndWrite();
delete section;
}


当执行完Execute后,为什么不会进入~CCLTP()?
谢谢
...全文
228 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzbinfo 2011-01-12
  • 打赏
  • 举报
回复
在你的线程构造函数中加一句
FreeOnTerminate = true;
试试
lyyanzi 2011-01-11
  • 打赏
  • 举报
回复
void __fastcall CCLTP::CLTPXQALTCHD()
{
int index1,index2;
DriveInfoIndex=-1;
AnsiString s_DeviceIP="";
if(Find(strFileName,"_",1,1,index1))
{
s_DeviceIP=strFileName.SubString(1,index1-1) ;
}
else
{
return;
}
for(int i=0;i<g_count;i++)
{
if(s_DeviceIP==g_pDriveInfo[i].IPID)
{
DriveInfoIndex=i;
break;
}
}
if(DriveInfoIndex==-1)
{
CopyFileTo("D:\\未处理图片\\"+strFileName,FileName);
return;
}
if((Find(strFileName,"_",1,6,index1))&&(Find(strFileName,"_",1,9,index2)))
{
g_pCLInfo->FXBH=ConvertFXBH1(strFileName.SubString(index1+1,index2-index1-1)) ; //方向编号
}
if((Find(strFileName,"_",1,1,index1))&&(Find(strFileName,"_",1,2,index2)))
{
g_pCLInfo->JGSJ=strFileName.SubString(index1+1,index2-index1-1) ;
}
if((Find(strFileName,"_",1,9,index1))&&(Find(strFileName,"_",1,10,index2)))
{
g_pCLInfo->XHDZT=IntToStr(StrToInt(strFileName.SubString(index1+1,index2-index1-1))-30) ;
}
if((Find(strFileName,"_",1,9,index1))&&(Find(strFileName,"_",1,12,index2)))
{
g_pCLInfo->SCZ=IntToStr(StrToInt(strFileName.SubString(index1+1,2))-30)+IntToStr(StrToInt(strFileName.SubString(index1+4,2))-30)+IntToStr(StrToInt(strFileName.SubString(index1+7,2))-30) ;
}
else
{
g_pCLInfo->SCZ="-";
}
if(g_pCLInfo->XHDZT=="1") //绿灯卡口
{
g_pCLInfo->WFXW="" ;
g_pCLInfo->SFWZ="0" ;
g_pCLInfo->SRSC="1" ;
}
else
{
g_pCLInfo->WFXW="13020" ;
g_pCLInfo->SFWZ="1" ;
g_pCLInfo->SRSC="1" ;
}
Form1->ShibieTP(FileName,DriveInfoIndex,g_pCLInfo->FXBH,g_pCLInfo->HPHM,g_pCLInfo->HPYS);
/*处理图片*/
if(g_BBH=="1")
{
SAVEXQALTCHD1();
}
}


void _fastcall CCLTP::SAVEXQALTCHD1()
{
AnsiString time1,time2,time3;
if(g_pCLInfo->XHDZT=="0")//闯红灯
{
/*找到车辆序号*/
/* AnsiString clxh="";
int index,index1,index2,index3;
if(Find(strFileName,"_",1,14,index))
{
clxh=strFileName.SubString(index+1,2);
}
TSearchRec src;
if(FindFirst(strFilePath+"*.jpg",faAnyFile,src)==0)
{
do
{
if(src.Name.Length()>3)
{
if((Find(src.Name,"_",1,2,index1))&&(Find(src.Name,"_",1,9,index2)))
{
//找到车道号相同的
if(src.Name.SubString(index1+1,index2-index1-1)==strFileName.SubString(index1+1,index2-index1-1))
{
//红灯第一张图片
if((Find(src.Name,"_",1,12,index1))&&(Find(src.Name,"_",1,9,index2))&&(Find(src.Name,"_",1,11,index3)))
{
if((src.Name.SubString(index1+1,2)=="21")&&(src.Name.SubString(index2+1,2)=="30")&&(src.Name.SubString(index3+1,2)==clxh) )
{
aFileName=src.Name;
}
}
//红灯第二张图片
if((Find(src.Name,"_",1,15,index1))&&(Find(src.Name,"_",1,9,index2))&&(Find(src.Name,"_",1,14,index3)))
{
if((src.Name.SubString(index1+1,2)=="21")&&(src.Name.SubString(index2+1,2)=="30")&&(src.Name.SubString(index3+1,2)==clxh) )
{
bFileName=src.Name;
if(Find(src.Name,"_",1,11,index1))
{
g_pCLInfo->HDGHSJ=FormatFloat("000",(StrToInt(src.Name.SubString(index1+1,2))-30)*100+(StrToInt(src.Name.SubString(index1+4,2))-30)*10+(StrToInt(src.Name.SubString(index1+7,2))-30));
}
}
}
//自身图片
else if(src.Name==FileName)
{
break;
}
if((aFileName!="")&&(bFileName!=""))
{
break;
}
}
}
}
}while(FindNext(src)==0);
FindClose(src);
} */
/*判断两张图片的时间
if((aFileName!="")&&(bFileName!=""))
{

if(Find(aFileName,"_",1,1,index1))
{
time1=aFileName.SubString(index1+1,17);
time3=strFileName.SubString(index1+1,17);
time2=bFileName.SubString(index1+1,17);
int timespan1=timebetween(time1,time2,0);
int timespan2=timebetween(time2,time3,0);
if((timespan1>g_HDSJ)||(timespan2>g_HDSJ)||(timespan1<0)||(timespan2<0))
{
aFileName="";
bFileName="";
}
}
} */
}
/*保存第三张图片到卡口接口*/
SAVEALTKK1();
/*保存三张图片到闯红灯接口*/
/* if((aFileName!="")&&(bFileName!=""))
{
SAVEALTCHD1(time1,time2,time3);
} */

}

void _fastcall CCLTP::SAVEALTKK1() //保存奥灵通卡口模式版本1
{
TJPEGImage *jpg=new TJPEGImage();
TJPEGImage *jpg1=new TJPEGImage();
Graphics::TBitmap *bmp=new Graphics::TBitmap;
Graphics::TBitmap *bmp1=new Graphics::TBitmap;
TStringStream *stream=new TStringStream("");
//byte *buffer;
int length;
AnsiString base641="",base642="",base643="",base64tx="";
try
{
AnsiString WriteText1,WriteText2,pathFileName;
AnsiString FXMS;
if(g_pCLInfo->FXBH.SubString(1,1) =="E")
{
FXMS="由西向东";
}
else if(g_pCLInfo->FXBH.SubString(1,1)=="S")
{
FXMS="由北向南";
}
else if(g_pCLInfo->FXBH.SubString(1,1)=="W")
{
FXMS="由东向西";
}
else if(g_pCLInfo->FXBH.SubString(1,1)=="N")
{
FXMS="由南向北";
}
WriteText2 ="";
WriteText1 = "时间:"+g_pCLInfo->JGSJ.SubString(1,4)+"年"+g_pCLInfo->JGSJ.SubString(5,2)+"月"+g_pCLInfo->JGSJ.SubString(7,2)+"日"+g_pCLInfo->JGSJ.SubString(9,2)+"时"+g_pCLInfo->JGSJ.SubString(11,2)+"分"+g_pCLInfo->JGSJ.SubString(13,2)+"秒"+" 地点:"+g_pDriveInfo[DriveInfoIndex].DDMS+" 方向:"+FXMS+" 车道号:"+g_pCLInfo->FXBH.SubString(2,2) ;
if(g_pCLInfo->SCZ!="-")
{
WriteText1 =WriteText1+" 车辆速度:"+g_pCLInfo->SCZ+"Km/h";
}
bmp1->Width=2592;
bmp1->Height=1944;
jpg1->LoadFromFile(FileName);
bmp1->Assign(jpg1);
/* bmp->Width=2592;
bmp->Height=1944+g_WordWidth;
bmp->Canvas->Font->Name="宋体";
bmp->Canvas->Font->Color =clRed;
bmp->Canvas->Font->Size =g_FontSize;
bmp->Canvas->Brush->Style = bsSolid;
bmp->Canvas->CopyRect(TRect(0,g_WordWidth,2592,1944+g_WordWidth),bmp1->Canvas,TRect(0,0,2592,1944)) ;
bmp->Canvas->TextOutA(3,3,WriteText1); */
jpg->Assign(bmp1); //ceshi
jpg->CompressionQuality=g_Compressrate;
jpg->Compress();
stream->Size=0;
jpg->SaveToStream(stream);
/*length=stream->Size;
stream->Position=0;
buffer=new byte[length];
stream->ReadBuffer(buffer,length);
base641=Base64Encode(buffer,length); */
base641=EncodeString(stream->DataString);
/*车牌特写*/
if((g_pCLInfo->HPHM!="-")&&(FileExists("d:\\"+g_pCLInfo->HPHM+".jpg")))
{
stream->Size=0;
jpg->LoadFromFile("d:\\"+g_pCLInfo->HPHM+".jpg");
jpg->SaveToStream(stream);
/*length=stream->Size;
stream->Position=0;
buffer=new byte[length];
stream->ReadBuffer(buffer,length);
base64tx=Base64Encode(buffer,length); */
base64tx=EncodeString(stream->DataString);
}
/*写入接口*/
AnsiString xml="<?xml version=""1.0"" encoding=""GBK""?><root><surveil><jgsj>"+g_pCLInfo->JGSJ+"</jgsj><jgdd>"+g_pDriveInfo[DriveInfoIndex].DDBH+"</jgdd><xsfx>"+ConvertFXBH(g_pCLInfo->FXBH.SubString(1,1))+"</xsfx><cdbh>"+g_pCLInfo->FXBH.SubString(2,2)+"</cdbh><sbbh>"+g_pDriveInfo[DriveInfoIndex].SBBH+"</sbbh><cjjg>"+CJJG+"</cjjg><cjfs>"+g_pDriveInfo[DriveInfoIndex].CJFS+"</cjfs><hphm>"+g_pCLInfo->HPHM+"</hphm><hpzl>"+g_pCLInfo->HPZL+"</hpzl>";
if(g_pCLInfo->SCZ!="-")
{
xml+="<scz>"+g_pCLInfo->SCZ+"</scz>";
}
if(g_pDriveInfo[DriveInfoIndex].ZGXS!="-")
{
xml+="<bzz>"+g_pDriveInfo[DriveInfoIndex].ZGXS+"</bzz>";
}
xml+="<hpys>"+g_pCLInfo->HPYS+"</hpys><wfxw>"+g_pCLInfo->WFXW+"</wfxw><zpstr1>"+base641+"</zpstr1><zpstr2>"+base642+"</zpstr2><zpstr3>"+base643+"</zpstr3><cptx>"+base64tx+"</cptx></surveil></root>";
g_KKJLNUM++;
if(g_KKJLNUM==-1)
{
g_KKJLNUM=1;
}
IWFData *WFData;
AnsiString result="";
/*while(result.Pos("数据下载成功")<0)
{
result=WFData->WriteWFData(IntToStr(g_WFJLNUM),xml);
} *///CESHI
/* AnsiString ceshi=DecodeString(base641);
TStringStream *ceshiStream=new TStringStream(ceshi);
TJPEGImage *ceshiJPG=new TJPEGImage();
ceshiJPG->LoadFromStream(ceshiStream);
ceshiJPG->SaveToFile("d:\\ceshi.jpg");
delete ceshiJPG; */
// delete buffer; buffer=NULL;
delete stream; stream=NULL;
delete jpg;
delete jpg1;
delete bmp1; bmp1=NULL;
delete bmp; bmp=NULL;
}
catch(...)
{
// delete buffer; buffer=NULL;
delete stream; stream=NULL;
delete jpg;
delete jpg1;
delete bmp1; bmp1=NULL;
delete bmp; bmp=NULL;
}
}
zzbinfo 2011-01-11
  • 打赏
  • 举报
回复
你这段执行完了不代表你的线程对象就没有了呀,你设置了自动释放才会销毁对象的,
lyyanzi 2011-01-11
  • 打赏
  • 举报
回复
//---------------------------------------------------------------------------
void __fastcall CCLTP::Execute()
{
if(Method==0) //如果是视频傲灵通闯红灯模式
{
CLTPSPALTCHD();
}
else if(Method==1) //如果是线圈傲灵通闯红灯模式
{
CLTPXQALTCHD();
}
TMultiReadExclusiveWriteSynchronizer *section=new TMultiReadExclusiveWriteSynchronizer();
section->BeginWrite();
Form1->ShowCLXX(g_pCLInfo->HPHM,g_pCLInfo->FXBH,g_pCLInfo->JGSJ.SubString(1,4)+"-"+g_pCLInfo->JGSJ.SubString(5,2)+"-"+g_pCLInfo->JGSJ.SubString(7,2)+" "+g_pCLInfo->JGSJ.SubString(9,2)+":"+g_pCLInfo->JGSJ.SubString(11,2)+":"+g_pCLInfo->JGSJ.SubString(13,2),g_pDriveInfo[DriveInfoIndex].DDMS,g_pCLInfo->SCZ,g_pCLInfo->SFWZ,g_pCLInfo->XHDZT,g_pCLInfo->SRSC,g_pCLInfo->HDGHSJ,strFilePath+strFileName);
section->EndWrite();
delete section;
if(aFileName!="")
{
DeleteFile(strFilePath+aFileName);
}
if(bFileName!="")
{
DeleteFile(strFilePath+bFileName);
}
DeleteFile(strFilePath+strFileName);
if(g_pCLInfo->HPHM!="-")
{
DeleteFile("D:\\"+g_pCLInfo->HPHM+".jpg");
}
}

执行完了不相当于线程就结束了吗
zzbinfo 2011-01-11
  • 打赏
  • 举报
回复
执行的呀,你是怎么结束的线程呀

13,826

社区成员

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

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