1
1
{ ***************************************************************************
2
2
3
- Copyright (c) 2015-2019 Kike Pérez
3
+ Copyright (c) 2015-2021 Kike Pérez
4
4
5
5
Unit : Quick.FileMonitor
6
6
Description : Watch for single file changes
7
7
Author : Kike Pérez
8
8
Version : 1.2
9
9
Created : 11/09/2017
10
- Modified : 29/01/2019
10
+ Modified : 10/05/2021
11
11
12
12
This file is part of QuickLib: https://github.com/exilon/QuickLib
13
13
@@ -65,6 +65,7 @@ TFileMonitor = class(TThread)
65
65
fModifedDate : TDateTime;
66
66
fCurrentMonitorNotify : TMonitorNotify;
67
67
fOnChangeNotify : TFileChangeNotify;
68
+ fIsThreadStarted : Boolean;
68
69
procedure SetEnabled (Status : Boolean);
69
70
procedure NotifyEvent ;
70
71
protected
@@ -86,6 +87,8 @@ implementation
86
87
constructor TFileMonitor.Create;
87
88
begin
88
89
inherited Create(True);
90
+ fIsThreadStarted := False;
91
+ fEnabled := False;
89
92
Self.FreeOnTerminate := False;
90
93
fInterval := 1000 ;
91
94
fExists := False;
@@ -166,17 +169,23 @@ procedure TFileMonitor.Execute;
166
169
167
170
procedure TFileMonitor.SetEnabled (Status : Boolean);
168
171
begin
169
- if (Status) and { $IFNDEF FPC} (not Started){ $ELSE} (Suspended){ $ENDIF} then Start;
170
-
171
172
if fEnabled <> Status then
172
173
begin
173
- fEnabled := Status;
174
- // gets current values
175
- if TFile.Exists(fFileName) then
174
+ if Status then
176
175
begin
177
- fExists := True;
178
- fModifedDate := TFile.GetLastWriteTime(fFileName);
176
+ // gets current values
177
+ if TFile.Exists(fFileName) then
178
+ begin
179
+ fExists := True;
180
+ fModifedDate := TFile.GetLastWriteTime(fFileName);
181
+ end ;
179
182
end ;
183
+ if not fIsThreadStarted then
184
+ begin
185
+ fIsThreadStarted := True;
186
+ if (Status) and { $IFNDEF FPC} (Started = False){ $ELSE} (Suspended){ $ENDIF} then Start;
187
+ end ;
188
+ fEnabled := Status;
180
189
end ;
181
190
end ;
182
191
0 commit comments