procedure TDispose.BatchRun;
var
PicturePathlist: TStringlist;
i,j,passCnt,unpassCnt,passPercnt: Integer;
PictureCnt:integer;
// chat :boolean;
starttime,endtime,costtime: integer;
speed: real;
begin
GroupBox3a.Visible := false;
Button3a.Enabled:= false; starttime:= GetTickCount;
isCanLookPic:=false;
if cbDebug1.Checked then
begin
showmessage('请退出调试模式');
isCanLookPic:=true;
exit;
end; memo2a.Text:='';
if not directoryExists(folderPath+'\..\不合格照片') then mkDir(folderPath+'\..\不合格照片');
if not directoryExists(folderPath+'\..\合格照片') then mkDir(folderPath+'\..\合格照片'); DeleteDirectory(folderPath+'\..\不合格照片\');
DeleteDirectory(folderPath+'\..\合格照片\');
if sqlSearch(adoPicMsg1,'select * from pictureMsg') then
sqlExecute(adoPicMsg1,'delete * from pictureMsg'); sqlstr:='insert into pictureMsg('; PicturePathlist := MakeFileList(folderPath, '.*');
memo2a.Lines.Add('此文件夹照片一共有 '+inttostr(PicturePathlist.count)+' 张');
passCnt:=0;
unpassCnt:=0;
progressbar1a.Position:=0;
progressbar1a.min:=0;
progressbar1a.Max:=PicturePathlist.count;
PictureCnt:=0;
for i := 0 to PicturePathlist.count - 1 do
begin
mainshowStr:='';
fieldNameStr:='';
fieldValueStr:='';
sqlstr:='insert into pictureMsg (';
fileName:=Copy( ExtractFileName(PicturePathlist.strings[i]),0,LastDelimiter( '. ',ExtractFileName(PicturePathlist.strings[i]) ) - 1);
mainShowStr:=mainShowStr+'文件名: '+fileName; fieldNameStr:=fieldNameStr+'name';
fieldValueStr:=fieldValueStr+' '' '+ fileName+' '' '; mainshowStr:='';
//chat := true;
if LoadPicture(PicturePathlist.strings[i]) then
begin
if CheckBlueClarity then
begin
if findEyes then
begin
if CheckClarity then
begin
inc(passCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''合格'' ';
Application.ProcessMessages;
end else begin
inc(unpassCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\不合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''不合格'' ';
Application.ProcessMessages;
end;
end else begin
inc(unpassCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\不合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''不合格'' ';
Application.ProcessMessages;
end;
end else begin
inc(unpassCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\不合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''不合格'' ';
Application.ProcessMessages;
end;
end else begin
inc(unpassCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\不合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''不合格'' ';
Application.ProcessMessages;
end; // if LoadPicture(PicturePathlist.str9ings[i]) then
fieldNameStr:=fieldNameStr+',folderPath';
fieldValueStr:=fieldValueStr+', '' '+folderPath+' '' '; sqlstr:=sqlstr+fieldNameStr+') values ('+fieldValueStr+')';
SQLExecute(adoPicMsg1,sqlstr); inc(PictureCnt);
memo2a.Lines.Add('。已检测照片'+inttostr(PictureCnt)+'张');
progressbar1a.Position:=progressbar1a.Position+1; end; // for i := 0 to PicturePathlist.count - 1 do
//PicturePathlist.Free;
SQLSearch(adoPicMsg1,'select * from pictureMsg');
passPercnt:=trunc( passCnt /(passCnt+unpassCnt) * 100 + 0.5 );
endtime:= GetTickCount;
costtime:= endtime-starttime ;
speed:=(PictureCnt*1000) div costtime;
memo2a.Lines.Add('照片合格率='+inttostr(passPercnt)+'% 其中合格数='+inttostr(passCnt)+' , 不合格数='+inttostr(unpassCnt)
+', 耗时='+ floattostr(costtime/1000)+'s, 速度='+ floattostr(speed)+'张/s');
isCanLookPic:=true; GroupBox3a.Visible := true ;
Button3a.Enabled:= true;end;
procedure TDispose.Execute; //单击按钮执行TDispose线程
begin
FreeOnTerminate:= true;
Flock.Enter;
BatchRun;
Flock.Leave;
{ Place thread code here }
end;
其中CheckBlueClarity、findEyes 和CheckClarity三个函数是对图片进行处理看是否符合标准,后面我用临界区来进行多线程同步,目的是在移动窗体时处理不会暂停,结果实现了,但是如果我单击按钮运行多几次就会 发现,前面三个判断函数的判断结果会出错,某些数据会混乱,请问大神们有什么解决方法?我的程序有什么问题?
var
PicturePathlist: TStringlist;
i,j,passCnt,unpassCnt,passPercnt: Integer;
PictureCnt:integer;
// chat :boolean;
starttime,endtime,costtime: integer;
speed: real;
begin
GroupBox3a.Visible := false;
Button3a.Enabled:= false; starttime:= GetTickCount;
isCanLookPic:=false;
if cbDebug1.Checked then
begin
showmessage('请退出调试模式');
isCanLookPic:=true;
exit;
end; memo2a.Text:='';
if not directoryExists(folderPath+'\..\不合格照片') then mkDir(folderPath+'\..\不合格照片');
if not directoryExists(folderPath+'\..\合格照片') then mkDir(folderPath+'\..\合格照片'); DeleteDirectory(folderPath+'\..\不合格照片\');
DeleteDirectory(folderPath+'\..\合格照片\');
if sqlSearch(adoPicMsg1,'select * from pictureMsg') then
sqlExecute(adoPicMsg1,'delete * from pictureMsg'); sqlstr:='insert into pictureMsg('; PicturePathlist := MakeFileList(folderPath, '.*');
memo2a.Lines.Add('此文件夹照片一共有 '+inttostr(PicturePathlist.count)+' 张');
passCnt:=0;
unpassCnt:=0;
progressbar1a.Position:=0;
progressbar1a.min:=0;
progressbar1a.Max:=PicturePathlist.count;
PictureCnt:=0;
for i := 0 to PicturePathlist.count - 1 do
begin
mainshowStr:='';
fieldNameStr:='';
fieldValueStr:='';
sqlstr:='insert into pictureMsg (';
fileName:=Copy( ExtractFileName(PicturePathlist.strings[i]),0,LastDelimiter( '. ',ExtractFileName(PicturePathlist.strings[i]) ) - 1);
mainShowStr:=mainShowStr+'文件名: '+fileName; fieldNameStr:=fieldNameStr+'name';
fieldValueStr:=fieldValueStr+' '' '+ fileName+' '' '; mainshowStr:='';
//chat := true;
if LoadPicture(PicturePathlist.strings[i]) then
begin
if CheckBlueClarity then
begin
if findEyes then
begin
if CheckClarity then
begin
inc(passCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''合格'' ';
Application.ProcessMessages;
end else begin
inc(unpassCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\不合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''不合格'' ';
Application.ProcessMessages;
end;
end else begin
inc(unpassCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\不合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''不合格'' ';
Application.ProcessMessages;
end;
end else begin
inc(unpassCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\不合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''不合格'' ';
Application.ProcessMessages;
end;
end else begin
inc(unpassCnt);
CopyFile( PChar(PicturePathlist.strings[i]), PChar( folderPath+'\..\不合格照片\'+ExtractFileName(PicturePathlist.strings[i]) ), True);
fieldNameStr:=fieldNameStr+',result';
fieldValueStr:=fieldValueStr+',''不合格'' ';
Application.ProcessMessages;
end; // if LoadPicture(PicturePathlist.str9ings[i]) then
fieldNameStr:=fieldNameStr+',folderPath';
fieldValueStr:=fieldValueStr+', '' '+folderPath+' '' '; sqlstr:=sqlstr+fieldNameStr+') values ('+fieldValueStr+')';
SQLExecute(adoPicMsg1,sqlstr); inc(PictureCnt);
memo2a.Lines.Add('。已检测照片'+inttostr(PictureCnt)+'张');
progressbar1a.Position:=progressbar1a.Position+1; end; // for i := 0 to PicturePathlist.count - 1 do
//PicturePathlist.Free;
SQLSearch(adoPicMsg1,'select * from pictureMsg');
passPercnt:=trunc( passCnt /(passCnt+unpassCnt) * 100 + 0.5 );
endtime:= GetTickCount;
costtime:= endtime-starttime ;
speed:=(PictureCnt*1000) div costtime;
memo2a.Lines.Add('照片合格率='+inttostr(passPercnt)+'% 其中合格数='+inttostr(passCnt)+' , 不合格数='+inttostr(unpassCnt)
+', 耗时='+ floattostr(costtime/1000)+'s, 速度='+ floattostr(speed)+'张/s');
isCanLookPic:=true; GroupBox3a.Visible := true ;
Button3a.Enabled:= true;end;
procedure TDispose.Execute; //单击按钮执行TDispose线程
begin
FreeOnTerminate:= true;
Flock.Enter;
BatchRun;
Flock.Leave;
{ Place thread code here }
end;
其中CheckBlueClarity、findEyes 和CheckClarity三个函数是对图片进行处理看是否符合标准,后面我用临界区来进行多线程同步,目的是在移动窗体时处理不会暂停,结果实现了,但是如果我单击按钮运行多几次就会 发现,前面三个判断函数的判断结果会出错,某些数据会混乱,请问大神们有什么解决方法?我的程序有什么问题?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货