[DUG] Sending data between process on same computer on windows

Ross Levis ross at stationplaylist.com
Wed May 9 15:57:05 NZST 2007


In my case it's in a normal gui application at one end and a service type
application in the other which uses a timer to check for incoming commands.

 

I normally do something like this.

 

ShareRec.Filename := 'Whatever';

ShareRec.Command := 2;

While ShareRec.Command <> 0 do Sleep(10);

 

The service application detects the command = 2, does something with the
filename, and sets command to 0 when finished.  The While loop usually only
executes once so there is no delay for the user.. 

 

You could run this in a thread if it was going to take a while.

 

I didn't know about NewInstance to allocate the object where you need it.
There is still an issue with strings and pointers inside the object.  Simple
records work well enough for me.

 

Ross.

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Leigh Wanstead
Sent: Wednesday, 9 May 2007 14:51
To: NZ Borland Developers Group - Delphi List
Subject: RE: [DUG] Sending data between process on same computer on windows

 

Hi Ross,

 

Is the code sample inside a dos command line application or you start a
thread to do that communication?

 

TIA

 

Regards

Leigh

www.smootharm.com

-----Original Message-----
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]On
Behalf Of Ross Levis
Sent: Wednesday, May 09, 2007 2:24 PM
To: 'NZ Borland Developers Group - Delphi List'
Subject: RE: [DUG] Sending data between process on same computer on windows

I guess you've read the readme.txt which explains all the properties and
methods.  Install it as a component.  Drop the component on a form in 2
programs.

 

I use a record pointer to share.  Here is a small example.  My record
actually contains many more fields.

 

type

  TShareRec = record

    Command: Integer;

    Filename: String[255];

  End;

  PShareRec = ^TShareRec;  

 

Var

  ShareRec: PShareRec;

Begin

  SharedMemory.ShareName := 'Something';

  SharedMemory.Size := Sizeof(TShareRec);

  If not SharedMemory.OpenMemory then

    SharedMemory.CreateMemory;

  ShareRec := SharedMemory.MapMemory;  

 

The above will work in both apps.  You can then assign ShareRec.Command :=
1; for example, and the other app can see it instantly.

 

Be sure to UnmapMemory and CloseMemory when closing.

 

Don't use pointer types such as dynamic Strings or classes as they will not
work. 

 

Cheers,

Ross.

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Jason Coley
Sent: Wednesday, 9 May 2007 13:51
To: NZ Borland Developers Group - Delphi List
Subject: RE: [DUG] Sending data between process on same computer on windows

 

Do you have any samples on how to work this component, I can't find much on
the net about it either, apart from download links.

 

Jason

 

I would use shared memory.  I use this free component.

http://www.torry.net/vcl/system/appscommunications/sharedmemory.zip

 

It uses a memory mapped file system but without a physical file.  It can use
messages for triggering events at each end, but I actually use a variable in
a record which I check in a 10ms loop to know when to do something.  It
works very well.

 

Ross.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.adventureeducation.co.nz/pipermail/delphi/attachments/20070509/45d73431/attachment.html


More information about the Delphi mailing list