動作確認は以下のようなコードでやっています.
var
FolderWatch : array[0..15] of TplFolderWatcher;
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
for i := 0 to 2 do begin
FolderWatch[i].StartWatch(Handle);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
p : integer;
Options : TplFolderEventOptions;
begin
Options := [];
Options := Options + [evt_RENAMEITEM];
Options := Options + [evt_CREATE];
Options := Options + [evt_DELETE];
Options := Options + [evt_MKDIR];
Options := Options + [evt_RMDIR];
for p := 0 to 2 do begin
FolderWatch[p] := tplFolderWatcher.Create(Self);
FolderWatch[p].Tag := p;
FolderWatch[p].OnChange := plFolderWatcher1Change;
FolderWatch[p].Options := Options;
end;
FolderWatch[0].Directory := 'D:\0000';
FolderWatch[1].Directory := 'D:\AAA';
FolderWatch[2].Directory := ExtractFileDir(Application.ExeName);
end;
procedure TForm1.plFolderWatcher1Change(Sender: TObject; AEvent: Integer;
BeforeFullPath, BeforeFileName, AfterFullPath, AfterFileName: string);
begin
Memo1.Lines.Add(IntToStr(TplFolderWatcher(Sender).Tag) + ' ' +
BeforeFullPath);
end;
追記:
このコードをそのままテストしてみようという方は,usesにplFolderWatcherが
必要です.また,Formには,TMemoとTButtonを1つづつ配置します.
|