home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue54 / System / ThreadTest / Pg1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-01-05  |  1.2 KB  |  51 lines

  1. unit Pg1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls, ExtCtrls, FileSysThread;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Button3: TButton;
  13.     procedure Button1Click(Sender: TObject);
  14.     procedure Button3Click(Sender: TObject);
  15.     procedure FormDestroy(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.     MyThread1 : TFileSysNotifyThread;
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.DFM}
  29.  
  30. procedure TForm1.Button1Click (Sender: TObject);
  31. begin
  32.     if MyThread1 = Nil then MyThread1 := TFileSysNotifyThread.Create ('c:\Temp', File_Notify_Change_File_Name or File_Notify_Change_Dir_Name, MyThread1)
  33.     else ShowMessage ('Thread still running');
  34. end;
  35.  
  36. procedure TForm1.Button3Click (Sender: TObject);
  37. begin
  38.     if MyThread1 <> nil then MyThread1.Terminate else ShowMessage ('Thread not running');
  39. end;
  40.  
  41. procedure TForm1.FormDestroy (Sender: TObject);
  42. begin
  43.     // What if the thread var goes Nil after the check?
  44.     if MyThread1 <> Nil then begin
  45.         MyThread1.Terminate;
  46.         MyThread1.WaitFor;
  47.     end;
  48. end;
  49.  
  50. end.
  51.