Board index » delphi » HELP: Passing variables from one app to another??

HELP: Passing variables from one app to another??

Greetings,

I have two different Delphi 3 apps.  I want to pass a variable from one
app to another.  For instance, in app A the user hits a button and that
will pass a variable to app B so that app B can perform some function.
How is this done?  Thanks!!

Mark

 

Re:HELP: Passing variables from one app to another??


Three ideas:
1)If you are always starting the second program, you could pass
command-line parameters, and access them through PARAMSTR.
2) You could use DDE linking.  A DDE client application can control a
DDE server application, starting it if it is not already running.  
3) You could write to an ini file with one app, and have the other app
read the file periodically.

Hope this helps!
DMGoncalves

Quote
mark barry wrote:

> Greetings,

> I have two different Delphi 3 apps.  I want to pass a variable from one
> app to another.  For instance, in app A the user hits a button and that
> will pass a variable to app B so that app B can perform some function.
> How is this done?  Thanks!!

> Mark

Re:HELP: Passing variables from one app to another??


Assuming they are all running on the same machine - use dde.  DDE is a
communications protocol whereby one window (application) talks to another.
Make program A the dde server and b the client.

mark barry <mba...@altechcontrols.com> wrote in article
<34DB59DE.3...@altechcontrols.com>...

Quote
> Greetings,

> I have two different Delphi 3 apps.  I want to pass a variable from one
> app to another.  For instance, in app A the user hits a button and that
> will pass a variable to app B so that app B can perform some function.
> How is this done?  Thanks!!

> Mark

Re:HELP: Passing variables from one app to another??


Quote
mark barry (mba...@altechcontrols.com) wrote:

: I have two different Delphi 3 apps.  I want to pass a variable from one
: app to another.  For instance, in app A the user hits a button and that
: will pass a variable to app B so that app B can perform some function.
: How is this done?  Thanks!!

        I tackled this by having program A send program B a custom message - and then copying the variable to the clipboard as a custom format. In program B's event
handler for the message just retrieve the variable from the clipboard.. saves you from messing around with DDE.

--
                              Bed
                bedn...@yallara.cs.rmit.edu.au
            http://www.geocities.com/Hollywood/2430
"Loving you was like loving the dead" - Black No.1, Type O Negative

Re:HELP: Passing variables from one app to another??


Quote
>       I tackled this by having program A send program B a custom message - and
>then copying the variable to the clipboard as a custom format. In program B's
>event
>handler for the message just retrieve the variable from the clipboard.. saves
>you from messing around with DDE.

There are lots of solutions, but personally I'd be quite annoyed if
someone sold me an application that did this. I like to know what's
on the clipboard - for example sometimes I copy a URL from a news
posting and paste it into my browser half an hour or more later.

Using messages is a "classical" solution, and works well, but usually
if you want to "send" some data you would use the LParam of your message
as a pointer to that data. This is tidier, faster and easier than using
the clipboard.
--
Jeremy Collins

Re:HELP: Passing variables from one app to another??


In article <34DB59DE.3...@altechcontrols.com>
           mba...@altechcontrols.com "mark barry" writes:

Quote
> Greetings,

> I have two different Delphi 3 apps.  I want to pass a variable from one
> app to another.  For instance, in app A the user hits a button and that
> will pass a variable to app B so that app B can perform some function.
> How is this done?  Thanks!!

Mark,

I do this regularly using windows messages. I use the
RegisterWindowsMessage API call in each application to get the same,
but unique message number, then put the data I want to send in the
wParam and lParam of the message. The message can either be broadcast
to all application, or posted to  a specific application by getting
handle using the FindWindow API call.

eg:
var
  MsgID: word;
begin  
  MsgID:=RegisterWindowMEssage('A unique string');
  OtherAppHandle:=FindWindow('TApplication', 'Application NAme');

  PostMessage(hwnd_Broadcast, MSGID, 123, 45678);

  PostMessage(OtherAppHandle, MsgID, 321, 654312);
end;

If the data you want to send is too large to fit into wParam and
lParam, you can globally allocate some memory and pass the
handle to that memory in lParam. The other app can then lock the
memory block and read the contents. I have found that the
allocating and freeing of memory can be somewhat slow, so generally
try to allocate and free only once (at start up and close down).

HTH,

Mike Watson

--
Denison Mayes Group

Other Threads