Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to do application data exchange in Delphi without sockets?

I need a few of my related applications to communicate to each other (exchange data and initiate actions). Requirements are without packages and no sockets. So I guess that leaves named pipes, WM_CopyData (like Skype does it) and command parameters. What are your best practices?

like image 323
Mihaela Avatar asked May 25 '09 13:05

Mihaela


4 Answers

You probably have a couple of options.

Beyond what you already have:
DDE
Memory Mapped Files (MMF)
MailSlots

I would probably go with either the Pipes or the MMF.

There are a couple of free MMF components that you can download, Deborah Pate has a set of freeware classes you can use. MapFiles.zip

Check for MailSlots on Torry's site.

The final solution might be dependent on the amount, size and frequency of the data transfers that decide which option you choose.

like image 88
Vivian Mills Avatar answered Sep 28 '22 01:09

Vivian Mills


I would advise to use COM in this situation. (Attention: not COM+, not ActiveX, not OLE; COM, just COM.)

Since Delphi 7 (or an earlier version, I'm not sure), this is easily done by adding a Type Library to the project, and an Automation object.

Advantages are it's pretty widely supported, both within Delphi (the Type Library Editor has everything you need and updates your code, and COM internals and registering are catered for from the ComServ unit), and outside of Delphi (I use it in a number of project to interact with all sorts of applications: C++ projects, Word and Excel documents using VBA, oldskool ASP...).

An only disadvantage I encountered may be threading issues, in normal applications, a plain CoInitialize(nil); at application startup will do, in more complex applications, you need to think about 'threading apartments' or use free threading and do your own locking. (Which in some cases you've been doing already.)

like image 30
Stijn Sanders Avatar answered Sep 28 '22 03:09

Stijn Sanders


Another alternative which is dirt simple to implement is to use the database to pass information.

Not overly elegant, and it does use a lot of overhead, but if your application is already data-aware (ie has a database as part of it), then using a table or two to pass information is pretty easy.

like image 32
CessnaPilot Avatar answered Sep 28 '22 03:09

CessnaPilot


You could use simple files: One side writes to it, the other reads. If you need two way communication, just use two files, one for each direction.

Of course this is not really high performance.

like image 39
dummzeuch Avatar answered Sep 28 '22 01:09

dummzeuch