[DUG] Sending notification between programs
Jeremy Coulter
jscoulter at gmail.com
Wed Aug 18 18:00:34 NZST 2010
Another way, and one use for easily transmitting structure between apps.
i.e. no mucking around with ports etc. Is based around the "PostBox" (or is
it mailbox forget now) method.
I use Zylappcommunicator. Here is what the document says HTH,
Jeremy
ZylAppCommunicator 1.0
ZylAppCommunicator is a Delphi / C++Builder component which allows you to
communicate between one or more applications which are running on the same
computer.
Use ZylAppCommunicator if you want to easily communicate between your
applications.
Types:
TReceiveEvent = procedure(Sender: TObject; SenderHandle: HWND;
BufferType:Integer; Buffer: TStream) of object;
TZylAppCommunicator = class(TComponent)
Properties:
Enabled: Boolean - Enable / disable the communication.
Handle: HWND - Communicator identifier, unique for each communicator.
CommunicationPortID: String - CommunicationPortID must be unique for each
communication protocol (implemented by you between two or more applications)
to avoid communication interferences. When you register the component you
will get a set of recommended values for this property to avoid
interferences with other applications.
Version: Double - Version number of the component.
Methods:
constructor Create(AOwner: TComponent) - constructor
destructor Destroy() - destructor
procedure SendString(Target: HWND; Text: ShortString) - Sends string to a
target communicator, identified by the "Target" parameter. "Text" parameter
represents the string you want to send.
procedure SendString(Text: ShortString) - Sends string to all the
communicators with the same "CommunicationPortID". "Text" parameter
represents the string you want to send.
procedure SendBuffer(Target: HWND; var Buffer; const BufferSize: Integer;
const BufferType: Integer) - Sends data to a target communicator, identified
by the "Target" parameter. "Buffer" parameter represents the data you want
to send and it can be of any type. "BufferSize" represents the size of the
data in bytes you want to send. "BufferType" represents the type of data you
want to send and it must be different from 0, because 0 is reserved for
strings (SendString method).
procedure SendBuffer(var Buffer; const BufferSize: Integer; const
BufferType: Integer) - Sends data to all the communicators with the same
"CommunicationPortID". "Buffer" parameter represents the data you want to
send and it can be of any type. "BufferSize" represents the size of the data
in bytes you want to send. "BufferType" represents the type of data you want
to send and it must be different from 0, because 0 is reserved for strings
(SendString method).
function GetAvailableCommunicators(): TStringList - Returns the list of
communicator identifiers with the same CommunicationPortID.
Events:
OnReceive: TReceiveEvent = procedure(Sender: TObject; SenderHandle: HWND;
BufferType:Integer; Buffer: TStream)- fires when new data was received. The
parameter "SenderHandle" represents the identifier of the sender
communicator. The parameter BufferType contains the type of received data (0
= string, user defined data otherwise). The parameter "Buffer" contains the
received data.
Remark:
It is indicated to use this component with "Stop on Delphi exception" option
deactivated. You can do this from Delphi / C++Builder menu, "Tools/Debugger
Options/Language Exceptions/Stop on Delphi exceptions", otherwise you will
have a break at all the handled exceptions.
Usage:
Create two application and put one "ZylAppCommunicator" on each
application's main form. Set the "CommunicationPortID" of both communicators
to the same value.
You can send data between the communicators using the "SendString" and
"SendBuffer" methods and you can use the "OnReceive" method to process the
received data.
You can find a demo application in the archived package which shows you the
usage of "SendString" and "SendBuffer" methods and OnReceive event. Start
the demo in two instances (e.g: one from Delphi and one directly by the
included exe file) and you can communicate between the two applications.
-----Original Message-----
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Dennis Chuah
Sent: Wednesday, 18 August 2010 17:17
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Sending notification between programs
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" <johnkbird at paradise.net.nz>
Sent: Wednesday, August 18, 2010 4:43 PM
To: "NZ Borland Developers Group - Delphi List" <delphi at 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 at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
> unsubscribe
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe
More information about the Delphi
mailing list