diskscanner OnFileFound example
dcDiskScanner and dcMultiDiskScannre components
Return to Introduction  Previous page  Next page
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;

File not found.