Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 08/28/25 in all areas

  1. Whilst there are many Delphi components for detecting changes to file system folders they suffer from serious limitations: typically they only allow you to monitor a single folder they do not support the monitoring of specific files they rely on the FindFirstChangeNotification API which gives no information about what has changed, requiring an inefficient search. I have created a new file system monitoring library that addresses the above limitations. Features: Easy to use, but also suitable for heavy duty monitoring Single unit with no external dependencies Allows monitoring folders and/or specific files Uses the ReadDirectoryChangesW API which provides information about what exactly was changed A single instance of the component can handle the monitoring of many folders and/or files Uses an I/O completion port for efficient handling of large numbers of requests A single thread handles all requests A different notification handler can be specified for each request You can have multiple handlers for each folder or file When you monitor folders you can specify whether you want to also monitor subfolders Installation: You do not need to install the library. Just download or clone the repo and add the source subdirectory to the Library path. Usage: procedure TForm1.FormCreate(Sender: TObject); begin // Create the IFileSystemMonitor interface FFileSystemMonitor := CreateFileSystemMonitor; // Monitor a directory FFileSystemMonitor.AddDirectory(TPath.GetTempPath, False, HandleChange); // Also monitor a specific file FFileSystemMonitor.AddFile('pathtoyourfile', HandleChange); end; procedure TForm1.HandleChange(Sender: TObject; const Path: string; ChangeType: TFileChangeType); begin with lvEventList.Items.Add do begin Caption := GetEnumName(TypeInfo(TFileChangeType), Integer(ChangeType)); SubItems.Add(Path); end; end; To stop monitoring a specific file or folder you use the following methods: function RemoveDirectory(const Directory: string; OnChange: TMonitorChangeHandler): Boolean; function RemoveFile(const FilePath: string; OnChange: TMonitorChangeHandler): Boolean;
  2. We have had these Delphi FMX guides available for a while, and I thought it could be useful to share them here: How to use Google Maps to determine the user's location in the Embarcadero Delphi FMX app: https://www.softacom.com/blog/how-to-use-google-maps-to-determine-the-users-location-via-embarcadero-delphi-fmx-app/ - shows how to access the user's coordinates and display them on a map. How to save and read data from Google Sheets in an Embarcadero Delphi FMX app: https://www.softacom.com/blog/development/how-to-save-and-read-data-from-google-sheets-in-an-embarcadero-delphi-fmx-app/ How to implement multi-touch in an Embarcadero Delphi FMX app: https://www.softacom.com/blog/development/how-to-add-multi-touch-to-an-embarcadero-delphi-fmx-app/ - shows how to add multi-touch drawing support How to use gestures in an Embarcadero Delphi FMX app: https://www.softacom.com/blog/development/how-to-use-gestures-in-embarcadero-delphi-fmx-app/ - shows how to handle swipe, zoom, and rotate gestures How to master FastReport in Delphi: https://www.softacom.com/blog/development/mastering-fastreport-in-delphi-dynamic-file-reporting-and-visualization/ – shows how to create dynamic reports and charts How to send email via an Embarcadero Delphi FMX app using the Gmail API: https://www.softacom.com/blog/development/sending-email-via-embarcadero-delphi-fmx-app-by-using-api/ How to generate images in an Embarcadero Delphi FMX app: https://www.softacom.com/blog/development/image-generation-capabilities-with-delphi-fmx-application-via-openai-api-dall·e-models/ - shows how to use OpenAI DALL·E for image generation
  3. I'm based in Manila, Philippines.
  4. Anders Melander

    New file system monitoring component

    ...unless you also monitor the parent directory. Maybe make the polling optional?
  5. May I suggest "fluent interfaces" as an alternative to nested calls. Instead of using a record like a dumb data store that is only manipulated from the outside, you can put the methods that fiddle with the record's contents directly into the record itself and thus keep the code and the data closely together. Also, this enables one to use a so-called "fluent interface". Example: This is an example of a record that contains just one integer member, "data". In real life, you can make the record as complex as you want. type pMyrecord=^tMyRecord; tMyRecord=Record data:integer; Function Reset:pMyrecord; Function Add (x:integer):pMyrecord; Function Multiply (x:integer):pMyrecord; Function Divide (x:integer):pMyrecord; End; As you can see, all the methods in this record return a pointer, which simply points to the record itself. That is the "secret sauce" one needs to implement fluent interfaces. function tMyRecord.Add(x: integer): pMyrecord; begin data:=data+x; result:=@self; end; function tMyRecord.Divide(x: integer): pMyrecord; begin data:=data div x; result:=@self; end; function tMyRecord.Multiply(x: integer): pMyrecord; begin data:=data*x; result:=@self; end; function tMyRecord.Reset: pMyrecord; begin data:=0; result:=@self; end; Now the cool thing: All these methods can be concatenated and will be processed left-to-right. This produces very legible and compact code: procedure Test; var x:tmyrecord; begin x.reset.add(12).multiply(4).divide(2); end; (edit) Note that I didn't do a single heap allocation here, never manually passed the record as a parameter and never did a nested call. The data lives on the stack. If the record contains managed objects such as strings, these are disposed of automatically.
×