⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mythread.pas

📁 采用Delphi7+Oracle. 该软件是由交警人员对各个路口闯红灯违法照片进行有效保存
💻 PAS
字号:
unit MyThread;

interface

uses
  Classes,Windows, Messages, SysUtils, Variants,  Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, TFlatButtonUnit,inifiles,Jpeg;

type
  TMyThread = class(TThread)
  private
     picPath:String;
    { Private declarations }
  protected
    procedure Execute; override;
    function JpegIsOK(path:String):Boolean;  //检查图片格式是否正确
  public
    constructor Create(path:string);   //每次限于一个路径
  end;

implementation

uses PicEnter, dbConn;

{ Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure TMyThread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ TMyThread }

procedure TMyThread.Execute;
var
  filename:String;
  filesize:longint;
  picInfos:PICINFO;
  done:integer;
  findfile: TSearchRec;
  fullFilePath:String;
  photoxh:String;
  Start,Stop,TimeUsed:longint;
  picCount:Integer;  //记数功能
begin
  { Place thread code here }
   frmPicEnter.labInfo.Caption :='开始导入'+picPath+'路径下的图片!';
  // if   Terminated   then   break;
   try
    picCount:=0;
      //done:= FindFirst(picPath+'\\*.jpg',@picInfos,0);
    Start:=GetTickCount;
    while not findfirst(picPath+'\*.jpg',faAnyFile,findfile)<>0 do
    begin
      if Terminated then break;

      if findfirst(picPath+'\*.jpg',faAnyFile,findfile) = 0 then  //有图片
      begin
          findfirst(picPath+'\*.jpg',faAnyFile,findfile);
          fullFilePath:=picPath+'\'+findfile.Name ;  //文件全路径
          if JpegIsOK(fullFilePath)=true then
          begin
            picInfos:=dbConn.GetPicInfo(findfile.Name);
            photoxh:=dbConn.SavePicInfoToDB(picInfos);
            if photoxh<>'-1' then
            begin
                dbConn.SavePicPhotoToDB(fullFilePath,photoxh);
            end;
            DeleteFile(fullFilePath);
            picCount:=picCount+1;
          end;
      end
      else
      begin
          Stop:=GetTickCount;
          TimeUsed:=(Stop-Start) div 1000;     //使用了xxx秒[!21ki@][@21ki
          frmPicEnter.labInfo.Caption :=' 时间:'+IntToStr(TimeUsed) +'秒,总数目:'+IntToStr(picCount) + '张 '+picPath+' 下已没有图片! ';
          self.Terminate;
          frmPicEnter.btnBegin.Enabled := false;
          frmPicEnter.btnEnd.Enabled := false;
      end;
    end;
   except
     MessageBox(0,'导入图片出现异常,请重试!', '图片导入', 64);
   end;
end;


constructor TMyThread.Create(path: string);
begin
    picPath:=path;
    FreeOnTerminate := True;
    inherited Create(False);
end;
function TMyThread.JpegIsOK(path:String):Boolean;  //检查图片格式是否正确
var
  jpeg:TJPegImage;
begin
  jpeg:=TJPEGImage.Create;
  try
    jpeg.LoadFromFile(path);
    jpeg.Free ;
    result:=true;
  except
    jpeg.Free ;
    DeleteFile(path);
    result:=false;
  end;
end;

end.
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -