how to use DDE server

7.8k views Asked by At

Can I get a little code example to use DDE as a server? I know how to use the client part, but can't figure setting up my app to act as a server and receive data.

2

There are 2 answers

2
Warren  P On

It is so easy to use the DDE server that you don't even need sample code. You can do it just at designtime inside the Delphi form designer:

To create a server that sends out data:

  1. Drop a TDDEServerConv and TDDEServerItem on your form or data module.
  2. Connect the server item to the server conversation (set DDEServerItem1.ServerConv=DdeServerConv1 using object inspector, there is a drop down list, but double clicking it is enough).
  3. Set the DDEServerItem.Text value to some valid text value (ie 'A')

To receive data, you might want to have macros that are executed by the DDE client that pass data to the server. For this you use the DdeServerConv.OnExecuteMacro event. Try dumping the parameter Msg:TStrings to a memo like this:

  Memo1.Lines.Assign(Msg); 

Now save and run your project.

To test it in excel type in:

=Project1|DdeServerConv1!DdeServerItem1

The excel dde client syntax parts are Application name followed by vertical bar, conversation name, followed by exclamation mark, then item name.

And you will see the value (A, or whatever you put into the Text property in the item) appear in Excel.

That's a working single item DDE server without any code written by you.

I generally find that I create the conversations and the items at runtime, instead of at designtime, in a real world scenario that is more useful for me.

For older (non unicode) Delphi versions there is also a full featured commercial product called Django that helps a lot with DDE work.

I think also you might be looking for information on how to write a "DDE Poke" command handler on the delphi side. I don't have a demo for that. I tried it, and the obvious things didn' quite work right for me (the item on your server has an OnPoke event, I wrote a simple client, called PokeData, and it didn't work).

5
FrankCM On

Have a look in your Delphi installation for a folder called DDEDemo. It's a DDE project that Delphi use to ship with (I'm not 100% sure it's still included, but have a look). The demo includes a DDE client and server.

Edit - Try this link for some example code.