multidiskscanner OnFileFound event
Example
Return to Introduction  Previous page  Next page
Applies to
dcMultiDiskScanner and dcDiskScanner components.  

Declaration
type  
  TdcFileFoundEvent = procedure(Sender: TObject;   
    FileName, FileType: String; FileSize: Extended;  
    FileTime: TDateTime; FileAttributes: TdcScanAttributes;  
    LargeIcon, SmallIcon: TIcon; SysImageIndex: Integer;  
    TotalFiles: Integer; TotalSize: Extended) of object;  
 
property OnFileFound: TdcFileFoundEvent;  

Description
The OnFileFound event occurs when the dcMultiDiskScanner component found the file or directory (if saDirectory specified in the SearchAttributes) that matches to specified criteria (IncludeList / ExcludeList lists, SearchAttributes, SearchSize and SearchTime properties).  
 
Use the OnFileFound event handler to take specific action once the DiskScanner found files, and, for example, add this file to the list with search results. Please check out an example of handling this event.  

Parameter Meaning
FileNameThe name of found file with full path to this file. Use ExtractFileName and ExtractFilePath routines from SysUtils unit to split the file name and path.  
FileTypeThe type of file extension, if it was registered in the shell. If extension was not registered, return value will be "EXT file", where EXT is the file extension.  
FileSizeSize of found file in bytes. Use FloatToStr function to convert this value to string  
FileTimeTime of last modification;  
FileAttributesThe set of file attributes (Normal, Archive, ReadOnly, Hidden, System or Directory). See TdcScanAttributes type.  
LargeIcon,  
SmallIcon32x32 and 16x16 icons, associated with this file extension in the shell. If file has .EXE extension, icon will be extracted from executable file. If file is Icon, the Icon image will returned. tip These parameters will be NIL (NULL), if UseIcon property is False.  
SysImageIndexdetermines an icon index in the system ImageList. Use this parameter only if you're using dcSystemImageList component as source of images for the ListView. tip SysImageIndex will be retrieved even if UseIcon is False.  
TotalFilesTotal number of found files per current search session.  
TotalSizeTotal size of all files that found in current search session. Use FloatToStr function to convert this value to string.  

Notes
iiwarning The LargeIcon and SmallIcon will be retrieved only if UseIcons property is True.  

Example
Following example demonstrates how to handle the OnFileFound event of dcDiskScanner or dcMultiDiskScanner component. Let's say, we have the ResultsListView: TListView which we would like to fill with the search results and ImageList: TImageList which contains the 16x16 images associated with the file types.  
 
procedure TForm1.dcDiskScannerFileFound(Sender: TObject; FileName,  
  FileType: String; FileSize: Extended; FileTime: TDateTime;  
  FileAttributes: TdcScanAttributes;  
  LargeIcon, SmallIcon: TIcon; SysImageIndex: Integer;  
  TotalFiles: Integer; TotalSize: Extended);  
const  
  KBStr = 'KB';    
var  
  St: String;  
  ListItem: TListItem;  
begin  
  StatusBar.Panels[1].Text := 'Files ' + IntToStr(TotalFiles);  
  StatusBar.Panels[2].Text := 'Total size: ' + FloatToStr(TotalSize) + ' bytes';  
 
  ListItem := ListView1.Items.Add; // adding new item  
{** file name}  
  ListItem.Caption := FileName;  
{** file type}  
  ListItem.SubItems.Add(FileType);  
{** file size}  
  if not (saDirectory in FileAttributes) then  
    if FileSize <> 0 then  
      St := FloatToStrF(Int(FileSize / 1024 + 1), ffNumber, 180) + KBStr  
    else  
      St := '0' + KBStr  
  else  
    St := '';  
  ListItem.SubItems.Add(St);  
{** file time}  
  ListItem.SubItems.Add(DateTimeToStr(FileTime));  
 
{** icon image }  
  ListItem.ImageIndex := SysImageIndex;  
  if saHidden in FileAttributes then  
    ListItem.Cut := True; { ghosted icon for hidden files }  
  St := LowerCase(ExtractFileExt(FileName));  
  { adding shortcut overlay for .lnk and .url }  
  if (St = '.lnk'or (St = '.url'then  
    ListItem.OverlayIndex := 1;  
 
{ //* Use code below if you don't want to use  
  //* system images and set DiskScanner1.UseIcons to True  
  ListItem.ImageIndex := ImageList1.Count;  
  ImageList1.AddIcon(SmallIcon); }  
end;  

See also
OnScanFolder, OnScanDone events;  
Execute, Stop methods.  
File not found.