John,

Use the simplest solution - a named event as suggested in the first
response.  Not only can you fire it from A whenever you need to, but you
do not need to have erroneous actions like renames to achieve the
triggering.  Far easier on the subsequent changes to the file to simply
fire event again than cause other renames. 

Regards,
Cameron

-----Original Message-----
From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz]
On Behalf Of Dennis Chuah
Sent: Wednesday, 18 August 2010 7:14 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Sending notification between programs


John,

Hi.  What I'd suggest is you use FILE_NOTIFY_CHANGE_FILE_NAME.  Program
A creates the file and writes to it using a temporary filename.  When it
is done writing, it renames the file to something that program B
recognises. 
This will trigger a FILE_NOTIFY_CHANGE_FILE_NAME and B can then pick up
the file.  Actually, creating the file will also trigger a
FILE_NOTIFY_CHANGE_FILE_NAME, but A is using a temporary filename that B
does recognise, B ignores it.

Regards,
Dennis.

--------------------------------------------------
From: "John Bird" <johnkb...@paradise.net.nz>
Sent: Wednesday, August 18, 2010 6:02 PM
To: "NZ Borland Developers Group - Delphi List" <delphi@delphi.org.nz>
Subject: Re: [DUG] Sending notification between programs

> The property
> FILE_NOTIFY_CHANGE_LAST_WRITE
>
> looks like a possibility, as if structured data has just been written
to a
> file this event should be triggered.   The only gotcha seems to be
that 
> the
> better the caching is the less likely the event will fire - according 
> to the help.  Tricky.
>
> John
>
>>
>> John,
>>
>> Hi.  What you want to use is WinAPI: FindFirstChangeNotification, 
>> FindNextChangeNotification and FindCloseChangeNotification in program
B.
>> Essentially, A writes to a file, and renames it.  This causes the 
>> handle returned by FindFirstChangeNotification to be signaled.  You 
>> can test for this using a loop and WaitForSingleObject / 
>> WaitForMulitipleObjects.  You can even specify a timeout in the 
>> WaitXXX calls so that B wakes periodically, even if there are nothing

>> signaled.  When the WaitXXX function returns, you can check for the 
>> existence of the file.
>>
>> Regards,
>> Dennis.
>>
>> --------------------------------------------------
>> From: "John Bird" <johnkb...@paradise.net.nz>
>> Sent: Wednesday, August 18, 2010 4:43 PM
>> To: "NZ Borland Developers Group - Delphi List" 
>> <delphi@delphi.org.nz>
>> Subject: [DUG]  Sending notification between programs
>>
>>> Which way would you favour to do the following ?
>>>
>>> I have two Delphi programs (A and B) that I will pass data from A to

>>> B - I will probably use  a file to put the data in because its quite

>>> structured.
>>> B will sleep on a timer loop until this something is triggered.
>>>
>>> What I want to do is send a simple notification from program A to B 
>>> that there is something to do - i.e. trigger an event in B to wake 
>>> and do something to process this.
>>>
>>> There are various ways I could communicate this notification
>>>
>>> 1 - Has to add minimal overhead of size and processing to programs A

>>> and B
>>> 2 - A can tolerate B not responding immediately without freezing but

>>> preferably will know
>>>
>>> The ways I have considered to be candidates are
>>>
>>> a - Windows messaging
>>> b - TCP/IP Indy   (which could send the data too.  (adds complexity
of
>>> needs to be done in a thread to not affect the main program A) c - 
>>> make program B a DLL d - Roll my own - make a timer in B which polls

>>> for for some condition and otherwise continues to sleep e - 
>>> something else.
>>>
>>> Kindly share your favoured options how you might do this.
>>>
>>> John
>>
>>
>>
>>> _______________________________________________
>>> NZ Borland Developers Group - Delphi mailing list
>>> Post: delphi@delphi.org.nz
>>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>>> Unsubscribe: send an email to delphi-requ...@delphi.org.nz with
Subject:
>>> unsubscribe
>>
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi@delphi.org.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-requ...@delphi.org.nz with
Subject:
>> unsubscribe
>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi@delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-requ...@delphi.org.nz with
Subject: 
> unsubscribe
> 
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject:
unsubscribe

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: 
unsubscribe

Reply via email to