home *** CD-ROM | disk | FTP | other *** search
- unit Pg1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls, ExtCtrls, FileSysThread;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Button3: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- private
- { Private declarations }
- MyThread1 : TFileSysNotifyThread;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Button1Click (Sender: TObject);
- begin
- if MyThread1 = Nil then MyThread1 := TFileSysNotifyThread.Create ('c:\Temp', File_Notify_Change_File_Name or File_Notify_Change_Dir_Name, MyThread1)
- else ShowMessage ('Thread still running');
- end;
-
- procedure TForm1.Button3Click (Sender: TObject);
- begin
- if MyThread1 <> nil then MyThread1.Terminate else ShowMessage ('Thread not running');
- end;
-
- procedure TForm1.FormDestroy (Sender: TObject);
- begin
- // What if the thread var goes Nil after the check?
- if MyThread1 <> Nil then begin
- MyThread1.Terminate;
- MyThread1.WaitFor;
- end;
- end;
-
- end.
-