?? easyfilesearch.pas
字號:
{****************************************************************************
* Project : EasyFileSearch component
* Author : Alexandre GAMBIER
* Date : 25/09/2002
* Unit : EasyFileSearch
* Prefixe :
* Purpose : Search file & folder
****************************************************************************
* Alexandre GAMBIER (25/09/2002) : File creation
* Alexandre GAMBIER (14/10/2002) : Replace OnFileFined event
* with OnFileFound
* Alexandre GAMBIER (14/10/2002) : Add exclude filters
* Alexandre GAMBIER (28/10/2002) : 1/ The LookForDirectory is not override
* by the LookForAnyFile
* 2/ The Filter property is replace by
* the FileNames property which allow to
* select more filters
* 3/ Add the OnAcceptFile event to allow
* user to decide if the must really
* be accept
****************************************************************************}
unit EasyFileSearch;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, FileSearch;
type
{ Search Options }
TOptionsKind = (okIncludeSubfolder, okLookForReadOnlyFile, okLookForHiddenFile, okLookForSystemFile, okLookForDirectory, okLookForArchiveFile, okLookForAnyFile);
TOptions = set of TOptionsKind;
{ Filters }
TFilterKind = (fkFilterOnDate, fkFilterOnSize);
TFilter = set of TFilterKind;
TEasyFileSearch = class(TComponent)
private
protected
{ Search Engine }
SearchEngine : TFileSearch;
{ Search Options }
fSearchOptions : TOptions;
{ Filters }
fFilterKind : TFilter;
fDateFilterFileAccess : TDateFilterAccessKind;
fDateFilterKind : TDateFilterKind;
fDateFilterFirstDate : TDateTime;
fDateFilterSecondDate : TDateTime;
fSizeFilterKind : TSizeFilterKind;
fSizeFilterSize : Integer;
{ Date Filter }
fDateOptions : TDateFilter;
{ Exclude Filter }
fExcludedFiles : TStrings;
{ FileNames }
fFileNames : TStrings;
{ Events }
fOnFileFound : TOnFileFound ;
fOnAcceptFile : TOnAcceptFile ;
fOnChangeFolder : TOnChangeFolder;
fOnStatistics : TOnStatistics ;
{ Version informations }
procedure SetVersion(NewVersion : String);
function GetVersion : String;
{ function for the ExcluedFilter options }
procedure SetExcludedFiles(NewExcluded : TStrings);
function GetExcludedFiles : TStrings;
{ functions for FileNames }
procedure SetFileNames(NewFileNames : TStrings);
function GetFileNames : TStrings;
{ functions for the search options }
procedure ConvertSearchOptions;
{ procedure SetFilter(NewFilter : String);
function GetFilter : String;}
procedure SetRootPath(NewRootPath : String);
function GetRootPath : String;
{ functions for the filter }
procedure ConvertFilterOptions;
{ function for events }
procedure pOnFileFound(FileFound : TFileInformations);
function pOnAcceptFile(FileFound : TFileInformations) : Boolean;
procedure pOnChangeFolder(NewPath : String);
procedure pOnStatistics(Stats : TStatistics);
public
{ Constructor & Destructor }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Start search operation }
function Search : Boolean;
published
{ Version }
property Version : String read GetVersion write SetVersion;
{ Search criteria }
property SearchOptions : TOptions read fSearchOptions write fSearchOptions;
{ Filters }
property FilterKind : TFilter read fFilterKind write fFilterKind ;
property DateFilterFileAccess : TDateFilterAccessKind read fDateFilterFileAccess write fDateFilterFileAccess;
property DateFilterKind : TDateFilterKind read fDateFilterKind write fDateFilterKind ;
property DateFilterFirstDate : TDateTime read fDateFilterFirstDate write fDateFilterFirstDate ;
property DateFilterSecondDate : TDateTime read fDateFilterSecondDate write fDateFilterSecondDate;
property SizeFilterKind : TSizeFilterKind read fSizeFilterKind write fSizeFilterKind ;
property SizeFilterSize : Integer read fSizeFilterSize write fSizeFilterSize ;
{ Exclude Filter }
property ExcludedFiles : TStrings read GetExcludedFiles write SetExcludedFiles;
{ FileNames }
property FileNames : TStrings read GetFileNames write SetFileNames;
property RootPath : String read GetRootPath write SetRootPath ;
{ Events }
property OnFileFound : TOnFileFound read fOnFileFound write fOnFileFound;
property OnAcceptFile : TOnAcceptFile read fOnAcceptFile write fOnAcceptFile;
property OnChangeFolder : TOnChangeFolder read fOnChangeFolder write fOnChangeFolder;
property OnStatistics : TOnStatistics read fOnStatistics write fOnStatistics;
end;
implementation
{*****************************************************************************
* Procedure : TEasyFileSearch.Create
* Purpose : Constructor
* Arguments : NONE
* Result : NONE
*****************************************************************************
* Alexandre GAMBIER (25/09/2002) : Creation
*****************************************************************************}
constructor TEasyFileSearch.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{ Events }
fOnFileFound := nil;
fOnAcceptFile := nil;
fOnChangeFolder := nil;
fOnStatistics := nil;
{ Search Options }
fSearchOptions := [okIncludeSubfolder..okLookForAnyFile];
{ Filters }
fFilterKind := [] ;
fDateFilterFileAccess := dfakAnyFiles ;
fDateFilterKind := dfkSame ;
fDateFilterFirstDate := Date ;
fDateFilterSecondDate := Date ;
fSizeFilterKind := sfkSmallerOrEqualTo;
fSizeFilterSize := 0 ;
{ Exclude }
fExcludedFiles := TStringList.Create;
{ FileNames }
fFileNames := TStringList.Create;
fFileNames.Add('*.*');
{ Create search engine }
SearchEngine := TFileSearch.Create;
SearchEngine.OnFileFound := pOnFileFound ;
SearchEngine.OnAcceptFile := pOnAcceptFile ;
SearchEngine.OnChangeFolder := pOnChangeFolder;
SearchEngine.OnStatistics := pOnStatistics ;
end;
{*****************************************************************************
* Procedure : TEasyFileSearch.Destroy
* Purpose : Destructor
* Arguments : NONE
* Result : NONE
*****************************************************************************
* Alexandre GAMBIER (25/09/2002) : Creation
*****************************************************************************}
destructor TEasyFileSearch.Destroy;
begin
{ Free memory }
fExcludedFiles.Free;
fFileNames.Free;
SearchEngine.Free;
inherited Destroy;
end;
{*****************************************************************************
* Procedure : TEasyFileSearch.SetVersion
* Purpose : Don't do anything, just here showing the version property in
* the object inspector
* Arguments :
* Result :
*****************************************************************************
* Alexandre GAMBIER (25/09/2002) : Creation
*****************************************************************************}
procedure TEasyFileSearch.SetVersion(NewVersion : String);
begin
end;
{*****************************************************************************
* Procedure : TEasyFileSearch.GetVersion
* Purpose : Give version of the component
* Arguments : NONE
* Result : Return the version
*****************************************************************************
* Alexandre GAMBIER (25/09/2002) : Creation
*****************************************************************************}
function TEasyFileSearch.GetVersion : String;
begin
Result := 'TEasyFileSearch v1.02';
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -