home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Filefind / FFMAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1995-12-12  |  4KB  |  148 lines

  1. unit Ffmain;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, FileFind, ExtCtrls;
  8.  
  9. const
  10.   AppName = 'TFileFind demo';
  11.  
  12. type
  13.   TForm1 = class(TForm)
  14.     FileFind1: TFileFind;
  15.     Label1: TLabel;
  16.     Edit1: TEdit;
  17.     ListBox1: TListBox;
  18.     Start: TButton;
  19.     Stop: TButton;
  20.     RadioGroup1: TRadioGroup;
  21.     CheckBox1: TCheckBox;
  22.     Close: TButton;
  23.     Total: TLabel;
  24.     procedure StartClick(Sender: TObject);
  25.     procedure StopClick(Sender: TObject);
  26.     procedure FileFind1Match(Sender: TObject);
  27.     procedure FileFind1ChangeDrive(Sender: TObject; NewDrive: Char);
  28.     procedure FileFind1ChangeDirectory(Sender: TObject;
  29.       NewDirectory: TFileName);
  30.     procedure RadioGroup1Click(Sender: TObject);
  31.     procedure CheckBox1Click(Sender: TObject);
  32.     procedure CloseClick(Sender: TObject);
  33.     procedure FormActivate(Sender: TObject);
  34.     procedure Edit1Change(Sender: TObject);
  35.     procedure FileFind1Stop(Sender: TObject; var CanStop: Boolean);
  36.   private
  37.     { Private declarations }
  38.     Count: Integer;
  39.   public
  40.     { Public declarations }
  41.   end;
  42.  
  43. var
  44.   Form1: TForm1;
  45.  
  46. implementation
  47.  
  48. {$R *.DFM}
  49.  
  50. procedure TForm1.StartClick(Sender: TObject);
  51. begin
  52.   Count := 0;
  53.   Total.Caption := '0';
  54.   ListBox1.Items.Clear;
  55.  
  56.   { enable/disable controls }
  57.   Start.Enabled := false;
  58.   Close.Enabled := false;
  59.   Edit1.Enabled := false;
  60.   CheckBox1.Enabled := false;
  61.   RadioGroup1.Enabled := false;
  62.   Stop.Enabled := true;
  63.  
  64.   { setup control }
  65.   FileFind1.FileName := Edit1.Text;
  66.  
  67.   { do it! }
  68.   try
  69.     FileFind1.Start;
  70.   finally
  71.  
  72.     { restore controls }
  73.     Start.Enabled := true;
  74.     Close.Enabled := true;
  75.     Edit1.Enabled := true;
  76.     CheckBox1.Enabled := true;
  77.     RadioGroup1.Enabled := true;
  78.     Stop.Enabled := false;
  79.  
  80.     Caption := AppName;
  81.     Application.Title := AppName;
  82.   end
  83. end;
  84.  
  85. procedure TForm1.StopClick(Sender: TObject);
  86. begin
  87.   FileFind1.Stop;
  88. end;
  89.  
  90. procedure TForm1.FileFind1Match(Sender: TObject);
  91. begin
  92.   ListBox1.Items.Add(FileFind1.LastMatch);
  93.   Inc(Count);
  94.   Total.Caption := IntToStr(Count);
  95. {  ListBox1.ItemIndex := ListBox1.Items.Count-1; }
  96. end;
  97.  
  98. procedure TForm1.FileFind1ChangeDrive(Sender: TObject; NewDrive: Char);
  99. begin
  100.   ListBox1.Items.Add('');
  101.   ListBox1.Items.Add('Drive '+NewDrive+':');
  102. end;
  103.  
  104. procedure TForm1.FileFind1ChangeDirectory(Sender: TObject;
  105.   NewDirectory: TFileName);
  106. begin
  107.   Caption := NewDirectory;
  108.   Application.Title := NewDirectory; { Try minimize when searching... }
  109. end;
  110.  
  111. procedure TForm1.RadioGroup1Click(Sender: TObject);
  112. begin
  113.   FileFind1.SearchScope := TSearchScope(RadioGroup1.ItemIndex);
  114. end;
  115.  
  116. procedure TForm1.CheckBox1Click(Sender: TObject);
  117. begin
  118.   FileFind1.StopOnFirstMatch := CheckBox1.Checked;
  119. end;
  120.  
  121. procedure TForm1.CloseClick(Sender: TObject);
  122. begin
  123.   Application.Terminate;
  124. end;
  125.  
  126. procedure TForm1.FormActivate(Sender: TObject);
  127. begin
  128.   Caption := AppName;
  129.   Application.Title := AppName;
  130.   Total.Caption := '';
  131.   Edit1.Text := '';
  132.   RadioGroup1.ItemIndex := Integer(FileFind1.SearchScope);
  133.   CheckBox1.Checked := FileFind1.StopOnFirstMatch;
  134. end;
  135.  
  136. procedure TForm1.Edit1Change(Sender: TObject);
  137. begin
  138.   Start.Enabled := Edit1.Text <> '';
  139. end;
  140.  
  141. procedure TForm1.FileFind1Stop(Sender: TObject; var CanStop: Boolean);
  142. begin
  143.   CanStop := MessageDlg('Do you really want to stop?',
  144.                 mtConfirmation,[mbYes,mbNo],0) = mrYes;
  145. end;
  146.  
  147. end.
  148.