我在哪里可以找到 System.IO 在 Delphi 11 上使用 FileSystemWatcher?

Where can I find System.IO to use FileSystemWatcher on Delphi 11?

如果在文件夹上创建了新文件,我需要实时监控。 System.IO.FileSystemWatcher 似乎是一个完美的解决方案。但是在 Delphi 11 它正在报告

[dcc32 Fatal Error] F2613 Unit 'System.IO' not found.

我是否必须下载一些东西才能获得 .pas 单元?

P.S。我探索了使用 windows API FindFirstChangeNotification 但这不提供创建的文件名。

System.IO.FileSystemWatcher 是 .net class 而不是 Delphi RTL 的一部分。因此你不会在任何地方找到它。

我认为您需要的API函数是ReadDirectoryChangesW

您还可以使用 DDNRuntime(Delphi .NET Framework/.NET Core Runtime)

https://github.com/ying32/DDNRuntime-examples

它可以帮助您轻松调用.net函数

喜欢

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;