Home  |  Delphi .net Home  |  System.IO.FileSystemWatcher  |  OnError Method
  
OnError  
Method  
A method that is called when a file system error is detected
FileSystemWatcher Class
System.IO NameSpace
NotCF1.  Procedure OnError ( Event : FileSystemEventArgs ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The OnError method is called when the Error event is triggered.
Notes
The author was unable to get the OnError method invoked in the sample code. Am awaiting a response from Borland to help on this matter.
Microsoft MSDN Links
System.IO
System.IO.FileSystemWatcher
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

// Class definition code
type
  MyWatcherClass = Class(System.IO.FileSystemWatcher)

    published
      procedure OnError (Events : ErrorEventArgs);
  end;

var
  MyWatcher : MyWatcherClass;

procedure MyWatcherClass.OnError(Events: ErrorEventArgs);
begin
  // It is crucial that the inherited OnError method is called
  inherited OnError(Events);

  // Indicate that we have detected a file or folder error
  Console.WriteLine(Events.ToString);
end;

// Main code
begin
  // Create an object inherited from the FileSystemWatcher class
  MyWatcher := MyWatcherClass.Create('C:\');

  // Watch for any file error
  MyWatcher.NotifyFilter := NotifyFilters.LastAccess;

  // Now we wait until an event occurs -
  // MyWatcher will notify us of changes
  MyWatcher.WaitForChanged(WatcherChangeTypes.Changed);

  Console.Readline;
end.
   It was expected that when incurring a file system error that the OnError method should be called, but this was not the case.
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author