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三個函式是對圖片進行處理看是否符合標準,后面我用臨界區來進行多執行緒同步,目的是在移動表單時處理不會暫停,結果實作了,但是如果我單擊按鈕運行多幾次就會 發現,前面三個判斷函式的判斷結果會出錯,某些資料會混亂,請問大神們有什么解決方法?我的程式有什么問題?
uj5u.com熱心網友回復:
我感覺你可以用一個更簡單的例子來reproduce這個錯誤轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/100397.html
標籤:語言基礎/算法/系統設計
