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

📄 unit_searchfilethread.pas

📁 用于制作和整理(文件搜索方式)编程技术文档和各类源代码, 可以如编程工具一样分色显示程序(C++, Delphi , java, Vb, SQL ……)(用算法实现), 主要用于查找相应的类和函数
💻 PAS
字号:
unit Unit_searchfileThread;

interface
    uses classes,windows,messages,sysUtils;

const WM_searchfile=Wm_user+$100;
////////////////////////////////////////////////
//                                            //
//     消息定义                               //
//     0 , 0 :开始                            //
//     1 , n  :现在搜索到第n 个了             //
//     2 , n  :第n个符合条件                  //
//     3 , 0 :  结束                          //
//                                            //
////////////////////////////////////////////////

type  TsearchKeyThread = class(TThread)
     private
      FMH:Thandle;
      FKey:string;
      Ffilelist:Tstringlist;
      Fpathstr:string;
      Ffiletype:string;
      Fsensitivity:boolean;
      slist:Tstringlist;

     protected
      procedure Execute; override;
      function findKeyword(index:integer):boolean;
     public
       constructor Create(Key:string;fileList:TstringList;pathstr:string;
       filetype:string;sensitivity:boolean;mainThreadHandle:Thandle);
       destructor Destroy; override;
     published

     end;

implementation
{ TsearchKeyThread }

constructor TsearchKeyThread.Create(Key: string; fileList: TstringList;
 pathstr:string;filetype:string;sensitivity:boolean;mainThreadHandle: Thandle);
begin
   inherited create(true);
   self.FMH :=mainThreadHandle;
  
   self.Ffilelist:=filelist ;
   self.Fpathstr :=pathstr;
   self.Ffiletype :=filetype;
   self.Fsensitivity :=sensitivity;
   self.slist:=Tstringlist.Create ;
   if self.Fsensitivity then
   begin
     self.FKey :=key
   end
   else
   begin
    self.FKey :=AnsiLowerCase(key);
   end;
end;

destructor TsearchKeyThread.Destroy;
begin
   postmessage(self.FMH, WM_searchfile,3,0);
   self.slist.Free ;
  inherited;
end;

procedure TsearchKeyThread.Execute;
 var    i:integer;
    count:integer;
    nextvalue:double;
    StepValue:double;

begin
  count:=self.Ffilelist.Count-1 ;

  stepValue:=count/100;
  nextvalue:=stepValue;

  for i:= 0 to  count do
  begin
     if self.Terminated then break;
     if i>nextvalue then
     begin
       postmessage(self.FMH,wm_searchfile,1,i);
       nextvalue :=nextvalue+stepvalue;

     end;
    ///////////////////////////////////////////////////////////////
     if self.findKeyword(i) then   //搜索到了
       postmessage(self.FMH, WM_searchfile,2,i);
    ////////////////////////////////////////////////////////////


  end;
  //   postmessage(self.FMH, WM_searchfile,3,0);
    postmessage(self.FMH,wm_searchfile,1,count);

end;

function TsearchKeyThread.findKeyword(index: integer): boolean;

begin
  if self.Fsensitivity then   //大小写敏感!
  begin
    slist.LoadFromFile(self.Fpathstr+self.Ffilelist.Strings[index]+self.Ffiletype );

    if pos(fkey,slist.Text )=0 then
       result:=false
    else
       result:=true;
  end
  else
  begin
    slist := Tstringlist.Create  ;
    slist.LoadFromFile(self.Fpathstr+self.Ffilelist.Strings[index]+self.Ffiletype );

    if pos(fkey,AnsiLowerCase(slist.Text) )=0 then
       result:=false
    else
       result:=true;

  end;

end;

end.





⌨️ 快捷键说明

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