'Where can I find System.IO to use FileSystemWatcher on Delphi 11?
I need to monitor real time if a new file is created on a folder. System.IO.FileSystemWatcher seems a perfect solution. But on Delphi 11 it is reporting
[dcc32 Fatal Error] F2613 Unit 'System.IO' not found.
Do I have to download something to have the .pas unit?
P.S. I have explored using the windows API FindFirstChangeNotification but this does not provide the filename created.
Solution 1:[1]
System.IO.FileSystemWatcher is a .net class and not part of the Delphi RTL. Therefore you won't find it anywhere.
I think the API function you need is ReadDirectoryChangesW.
Solution 2:[2]
You can also use DDNRuntime(Delphi .NET Framework/.NET Core Runtime)
https://github.com/ying32/DDNRuntime-examples
It can help you call .net fuctions easyly
Just like
procedure TestMemoryStream;
var
LMem: DNMemoryStream;
LBytes: TArray<Byte>;
B: Byte;
LReadLen: Integer;
begin
LMem := TDNMemoryStream.Create;
LMem.Write([1,2,3,4,5], 0, 5);
LMem.WriteByte(121);
LMem.Flush;
LMem.Position := 0;
Writeln('data Length: ', LMem.Length);
SetLength(LBytes, LMem.Length);
LReadLen := LMem.Read(LBytes, 0, Length(LBytes));
Writeln('len: ', LReadLen);
for b in LBytes do
Write(b, ' ');
Writeln;
end;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Heffernan |
| Solution 2 |
