Skip to content

Commit d125959

Browse files
committed
FileMonitor small fixes
1 parent 6ed2aef commit d125959

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Quick.FileMonitor.pas

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Author : Kike Pérez
88
Version : 1.2
99
Created : 11/09/2017
10-
Modified : 25/01/2019
10+
Modified : 29/01/2019
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -65,17 +65,18 @@ TFileMonitor = class(TThread)
6565
fModifedDate : TDateTime;
6666
fCurrentMonitorNotify : TMonitorNotify;
6767
fOnChangeNotify : TFileChangeNotify;
68-
procedure Execute; override;
69-
procedure SetStatus(Status : Boolean);
68+
procedure SetEnabled(Status : Boolean);
7069
procedure NotifyEvent;
70+
protected
71+
procedure Execute; override;
7172
public
7273
constructor Create;
7374
destructor Destroy; override;
7475
property FileName : string read fFileName write fFileName;
7576
property Interval : Integer read fInterval write fInterval;
7677
property Notifies : TMonitorWatch read fNotifies write fNotifies;
7778
property OnFileChange : TFileChangeNotify read fOnChangeNotify write fOnChangeNotify;
78-
property Enabled : Boolean read fEnabled write SetStatus;
79+
property Enabled : Boolean read fEnabled write SetEnabled;
7980
end;
8081

8182
TQuickFileMonitor = TFileMonitor;
@@ -96,12 +97,12 @@ constructor TFileMonitor.Create;
9697
{$ELSE}
9798
fTickEvent := TSimpleEvent.Create(nil,True,False,'');
9899
{$ENDIF}
99-
Self.Resume;
100100
end;
101101

102102
destructor TFileMonitor.Destroy;
103103
begin
104104
if not Terminated then Terminate;
105+
Self.WaitFor;
105106
fTickEvent.SetEvent;
106107
fTickEvent.Free;
107108
inherited;
@@ -111,7 +112,7 @@ procedure TFileMonitor.Execute;
111112
var
112113
LastModifiedDate : TDateTime;
113114
begin
114-
inherited;
115+
inherited;
115116
while not Terminated do
116117
begin
117118
fCurrentMonitorNotify := mnNone;
@@ -163,8 +164,10 @@ procedure TFileMonitor.Execute;
163164
end;
164165
end;
165166

166-
procedure TFileMonitor.SetStatus(Status : Boolean);
167+
procedure TFileMonitor.SetEnabled(Status : Boolean);
167168
begin
169+
if (Status = True) and (Started = False) then Start;
170+
168171
if fEnabled <> Status then
169172
begin
170173
fEnabled := Status;

0 commit comments

Comments
 (0)