【问题标题】:Where can I find System.IO to use FileSystemWatcher on Delphi 11?在哪里可以找到 System.IO 以在 Delphi 11 上使用 FileSystemWatcher?
【发布时间】:2022-07-06 21:16:52
【问题描述】:

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

[dcc32 致命错误] 未找到 F2613 单元“System.IO”。

我必须下载一些东西才能拥有 .pas 单元吗?

附:我已经探索过使用 Windows API FindFirstChangeNotification 但这不提供创建的文件名。

【问题讨论】:

    标签: delphi delphi-11-alexandria


    【解决方案1】:

    System.IO.FileSystemWatcher 是一个 .net 类,不是 Delphi RTL 的一部分。因此,您在任何地方都找不到它。

    我想你需要的API函数是ReadDirectoryChangesW

    【讨论】:

    【解决方案2】:

    也可以使用 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-30
      • 2011-08-22
      • 2014-12-14
      • 2012-05-04
      相关资源
      最近更新 更多