ShellPlus Customer login
ShellPlus
Shell+ components
    Home
    News
    Overview
    Download
    Examples
    Customer's area
    Flash Demo
 
Developer Tools
    Shell Reset Tool
 
Shell+ Tutorial
    Namespace Extensions
    ShortCut menu
    Property Sheet
    Icon Handler
    Thumbnails
    InfoTip Handler
    Copy Hook
    Balloon TrayIcon
    Control Panel
    Shortcut Files
    Drag&Drop Menu
    Shell Change Notify
 
 
Documents
    Articles Index
    Press Releases
 
Purchase
    Buy now
    Resellers network
    Resellers wanted
 
Support
    Contact directly
    Customer's area
 
About/Contacts
    Shell+ Developers

Embarcader Technology Partner

 
Change Notifier Component Example

    This example shows the usage of TSxChangeNotifier component. Use this component if you have a need to monitor file modification, creation or deletion. The component allows you to monitor a single file as well as a group of files, you can use masks and monitor several directories in the folders tree. When file event occurs the TSxChangeNotifier calls corresponding event handler and reports the name of file that was changed.

    The example below shows how to use TSxChangeNotifier to monitor all files in a single directory.


    Create a new project: File -> New... -> Application and drop the TSxChangeNotifier onto its main form. Then add a couple of controls as shown below (you can download a ready example using a links below):

Example of File Change Notifier

    Save the project now.

    The next step is a configuration of TSxChangeNotifier properties. Use the data from the table below to set the properties:

Filters This property contains a list of filters. Only files that match the filter will be monitored by the component. Current example uses the *.* mask to monitor all files in the specified directory.
MaxLevels The depth of folders tree to be monitored. Use MaxLevels = 1 for this example.
Root This property should contain a path to the folder to be monitored. File monitoring will be performed in this folder as well as in its subfolders. The depth of monitoring is limited by MaxLevels and WatchSubtree properties.
WatchSubtree Set this property to False to prevent monitoring of subfolders. In other case set it to True.

Set button's event handlers now.  Code for the "Start" button is:

procedure TTestNotifierWindow.StartClick(Sender: TObject);
begin
  ChangeNotifier.Start;
end;

  The following code should be used for the "Stop" button:

procedure TTestNotifierWindow.StartClick(Sender: TObject);
begin
  ChangeNotifier.Stop;
end;

  The "Pause" works as:

procedure TTestNotifierWindow.btnPauseResumeClick(Sender: TObject);
begin
  if not ChangeNotifier.Paused then
  begin
    ChangeNotifier.Paused:=True;
    btnPauseResume.Caption:='Resume';
  end
  else
  begin
    ChangeNotifier.Paused:=False;
    btnPauseResume.Caption:='Pause';
  end;
end;

     The next handler is for "Clear" button:

procedure TTestNotifierWindow.StartClick(Sender: TObject);
begin
  ListView.Items.Clear;
end;

     Now it is a time to add code to component's event handlers. All three handlers are similar. The AddFile event should look like:

procedure TTestNotifierWindow.ChangeNotifierAddFile(Sender: TObject;
  FileInfo: TSxFileInfoEventData);
var
  ListItem:TListItem;
begin
  ListItem:=ListView.Items.Add;
  ListItem.Caption:='Created';
  ListItem.SubItems.Add(FileInfo.Filename);
  ListItem.SubItems.Add(DateTimeToStr(FileInfo.NewLastAccessTime));
end;

     The TSxChangeNotifier.OnChange event is handled as:

procedure TTestNotifierWindow.ChangeNotifierChange(Sender: TObject;
  FileInfo: TSxFileInfoEventData);
var
  ListItem:TListItem;
begin
  ListItem:=ListView.Items.Add;
  ListItem.Caption:='Modified';
  ListItem.SubItems.Add(FileInfo.Filename);
  ListItem.SubItems.Add(DateTimeToStr(FileInfo.OldLastWriteTime));
end;

     And the TSxChangeNotifier.OnDelete event should contain a code:

procedure TTestNotifierWindow.ChangeNotifierDelete(Sender: TObject;
  FileInfo: TSxFileInfoEventData);
var
  ListItem:TListItem;
begin
  ListItem:=ListView.Items.Add;
  ListItem.Caption:='Deleted';
  ListItem.SubItems.Add(FileInfo.Filename);
  ListItem.SubItems.Add(DateTimeToStr(FileInfo.OldLastAccessTime));
end;

    Save the project and compile it - it is ready now! Launch it and press the "Start" button. First of all the application will search for files that match the mask and will collect their data into internal database. These data will be used later to monitor changes.

    You can save this database to avoid re-scanning when application restarts. Use the PersistentRoot è RootImageFileName properties to do it. When the monitoring is stopped the database is dumped into the file, when monitoring is restarted the database will be restored. Another use of this feature - you can monitor changes even if the monitoring process was restarted.

    Use links below to download source codes of this example as well as binary files:

Delphi 10.1 Berlin (x64)
ChangeNotifier-D24X64.zip
28.59Kb
3.15.296.396
11.09.2016
Delphi 10.1 Berlin
ChangeNotifier-D24.zip
24.18Kb
3.15.296.396
11.09.2016
Delphi 10 Seattle (x64)
ChangeNotifier-D23X64.zip
28.20Kb
3.15.296.396
11.09.2016
Delphi 10 Seattle
ChangeNotifier-D23.zip
23.77Kb
3.15.296.396
11.09.2016
Delphi XE8 (x64)
ChangeNotifier-D22X64.zip
26.62Kb
3.12.289.357
15.05.2015
Delphi XE8
ChangeNotifier-D22.zip
22.06Kb
3.12.289.357
15.05.2015
Delphi XE7 (x64)
ChangeNotifier-D21X64.zip
26.55Kb
3.11.289.357
19.09.2014
Delphi XE7
ChangeNotifier-D21.zip
21.95Kb
3.11.289.357
19.09.2014
Delphi XE6 (x64)
ChangeNotifier-D20X64.zip
26.55Kb
3.10.287.331
16.09.2014
Delphi XE6
ChangeNotifier-D20.zip
21.89Kb
3.10.287.331
16.09.2014
Delphi XE5 (x64)
ChangeNotifier-D19X64.zip
24.43Kb
3.10.287.331
16.03.2014
Delphi XE5
ChangeNotifier-D19.zip
21.92Kb
3.10.287.331
16.03.2014
Delphi XE4 (x64)
ChangeNotifier-D18X64.zip
24.43Kb
3.10.287.331
16.03.2014
Delphi XE4
ChangeNotifier-D18.zip
21.91Kb
3.10.287.331
16.03.2014
Delphi XE3 (x64)
ChangeNotifier-D17X64.zip
24.43Kb
3.10.287.331
16.03.2014
Delphi XE3
ChangeNotifier-D17.zip
21.84Kb
3.10.287.331
16.03.2014
Delphi XE2 (x64)
ChangeNotifier-D16X64.zip
23.92Kb
3.10.287.331
16.03.2014
Delphi XE2
ChangeNotifier-D16.zip
21.86Kb
3.10.287.331
16.03.2014
Delphi XE
ChangeNotifier-D15.zip
18.63Kb
3.10.287.331
16.03.2014
Delphi 2010
ChangeNotifier-D14.zip
18.58Kb
3.10.287.331
16.03.2014
Delphi 2009
ChangeNotifier-D12.zip
17.02Kb
3.10.287.331
16.03.2014
Delphi 2007
ChangeNotifier-D11.zip
16.78Kb
3.10.287.331
16.03.2014
Delphi 2006
ChangeNotifier-D10.zip
16.74Kb
3.10.287.331
16.03.2014
Delphi 2005
ChangeNotifier-D9.zip
17.76Kb
3.10.287.331
16.03.2014
Delphi 7
ChangeNotifier-D7.zip
17.50Kb
3.12.289.357
16.05.2015
Delphi 6
ChangeNotifier-D6.zip
17.36Kb
3.8.287.331
09.05.2012

  Top


Components | Download | Purchase | Support | About Us
Copyright © 2016 ALDYN Software. All rights reserved.
Copyright © 2001 - 2011 Shell+ Development Group. All rights reserved.