Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 396405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:32:57+00:00 2026-05-12T16:32:57+00:00

I have very limited knowledge of using C Builder, could you give me an

  • 0

I have very limited knowledge of using C Builder, could you give me an example or point me to tutorial showing how to use FindNextChangeNotification in Delphi or ,if it is possible, how to use the C component in delphi?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:32:57+00:00Added an answer on May 12, 2026 at 4:32 pm

    The ReadDirectoryChanges seems to be the function that I am looking for. Here is my attempt using mghie’s code Why does ReadDirectoryChangesW omit events?

    My objective here is to monitor the directory/path or file you will see in Unit1. I just want a simple showmessage dialogue to popup whenever a change at the location is detected. I can’t find where I am supposed to pass my notification procedure or function. Unit2 just holds the unchanged code from mghie. When I compile this project and make a simple change in the directory nothing happens. I am using the ReadDirectoryChanges correctly?

    here is Unit1:

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Unit2;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      fthread:TWatcherthread;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    //start directory or file watch here
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
       fThread := TWatcherThread.Create('C:\Users\abe\Desktop\statcious\mitsu\Demo\abc.txt');
    
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
       if fThread <> nil then begin
        TWatcherThread(fThread).Shutdown;
        fThread.Free;
      end;
    end;
    
    end.
    

    Here is Unit2:

    unit Unit2;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;
    
    type
      TWatcherThread = class(TThread)
      private
        fChangeHandle: THandle;
        fDirHandle: THandle;
        fShutdownHandle: THandle;
      protected
        procedure Execute; override;
      public
        constructor Create(ADirectoryToWatch: string);
        destructor Destroy; override;
    
        procedure Shutdown;
    
      end;
    
    type
      TForm2 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form2: TForm2;
    
    implementation
    
    {$R *.dfm}
    
    constructor TWatcherThread.Create(ADirectoryToWatch: string);
    const
      FILE_LIST_DIRECTORY = 1;
    begin
      inherited Create(TRUE);
      fChangeHandle := CreateEvent(nil, FALSE, FALSE, nil);
      fDirHandle := CreateFile(PChar(ADirectoryToWatch),
        FILE_LIST_DIRECTORY or GENERIC_READ,
        FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE,
        nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_OVERLAPPED, 0);
      fShutdownHandle := CreateEvent(nil, FALSE, FALSE, nil);
      Resume;
    end;
    
    destructor TWatcherThread.Destroy;
    begin
      if fDirHandle <> INVALID_HANDLE_VALUE then
        CloseHandle(fDirHandle);
      if fChangeHandle <> 0 then
        CloseHandle(fChangeHandle);
      if fShutdownHandle <> 0 then
        CloseHandle(fShutdownHandle);
      inherited Destroy;
    end;
    
    procedure TWatcherThread.Execute;
    type
      PFileNotifyInformation = ^TFileNotifyInformation;
      TFileNotifyInformation = record
        NextEntryOffset: DWORD;
        Action: DWORD;
        FileNameLength: DWORD;
        FileName: WideChar;
      end;
    const
      BufferLength = 65536;
    var
      Filter, BytesRead: DWORD;
      InfoPointer: PFileNotifyInformation;
      Offset, NextOffset: DWORD;
      Buffer: array[0..BufferLength - 1] of byte;
      Overlap: TOverlapped;
      Events: array[0..1] of THandle;
      WaitResult: DWORD;
      FileName, s: string;
    begin
      if fDirHandle <> INVALID_HANDLE_VALUE then begin
        Filter := FILE_NOTIFY_CHANGE_FILE_NAME or FILE_NOTIFY_CHANGE_DIR_NAME
          or FILE_NOTIFY_CHANGE_SIZE or FILE_NOTIFY_CHANGE_LAST_WRITE;
    
        FillChar(Overlap, SizeOf(TOverlapped), 0);
        Overlap.hEvent := fChangeHandle;
    
        Events[0] := fChangeHandle;
        Events[1] := fShutdownHandle;
    
        while not Terminated do begin
          if ReadDirectoryChangesW (fDirHandle, @Buffer[0], BufferLength, TRUE,
            Filter, @BytesRead, @Overlap, nil)
          then begin
            WaitResult := WaitForMultipleObjects(2, @Events[0], FALSE, INFINITE);
            if WaitResult = WAIT_OBJECT_0 then begin
              InfoPointer := @Buffer[0];
              Offset := 0;
              repeat
                NextOffset := InfoPointer.NextEntryOffset;
                FileName := WideCharLenToString(@InfoPointer.FileName,
                  InfoPointer.FileNameLength);
                SetLength(FileName, StrLen(PChar(FileName)));
                s := Format('[%d] Action: %.8xh, File: "%s"',
                   [Offset, InfoPointer.Action, FileName]);
                OutputDebugString(PChar(s));
                PByte(InfoPointer) := PByte(DWORD(InfoPointer) + NextOffset);
                Offset := Offset + NextOffset;
              until NextOffset = 0;
            end;
          end;
        end;
      end;
    end;
    
    procedure TWatcherThread.Shutdown;
    begin
      Terminate;
      if fShutdownHandle <> 0 then
        SetEvent(fShutdownHandle);
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As
I have very limited knowledge of C#. My goal is to provide a C++
I have very limited knowledge with scripts so I hope you guys can help
I have a very limited knowledge about node and nob-blocking IO so forgive me
I'm very new to this and have limited knowledge (all self taught over the
I have very limited coding knowledge of OpenGL/Glut. I'm supposed to build house and
I'm unfamiliar with asyncore , and have very limited knowledge of asynchronous programming except
I'm rarely using java, so my knowledge of modern ecosystem is very limited :(.
I recently pickup Java so I have very limited knowledge, but I would like
I have a very limited knowledge on AS400 and RPG. But we have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.