如何使用DDE服务器
我可以获得一些使用 DDE 作为服务器的代码示例吗?我知道如何使用客户端部分,但无法将我的应用程序设置为充当服务器并接收数据。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 Delphi 安装中是否有名为 DDEDemo 的文件夹。这是 Delphi 用来附带的一个 DDE 项目(我不能 100% 确定它仍然包含在内,但请看一下)。该演示包括 DDE 客户端和服务器。
编辑 - 尝试使用链接获取一些示例代码。
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.
使用 DDE 服务器非常容易,您甚至不需要示例代码。您可以在 Delphi 表单设计器内的设计时执行此操作:
要创建发送数据的服务器:
表单或数据上的 TDDEServerItem
模块。
服务器对话(设置
DDEServerItem1.ServerConv=DdeServerConv1
使用对象检查器,有一个
下拉列表,但双击
就足够了)。
要接收数据,您可能需要由 DDE 客户端执行的宏来将数据传递到服务器。为此,您可以使用 DdeServerConv.OnExecuteMacro 事件。尝试将参数 Msg:TStrings 转储到如下备忘录中:
现在保存并运行您的项目。
要在 Excel 中测试它,请键入:
Excel dde 客户端语法部分是应用程序名称,后跟竖线,对话名称,后跟感叹号,然后是项目名称。
您将看到值(A,或您在项目的 Text 属性中输入的任何值)出现在 Excel 中。
这是一个工作的单项 DDE 服务器,无需您编写任何代码。
我通常发现我在运行时而不是在设计时创建对话和项目,在现实场景中对我来说更有用。
对于较旧的(非 unicode)Delphi 版本,还有一个名为 Django 的全功能商业产品,它对 DDE 工作有很大帮助。
我想您也可能正在寻找有关如何在 delphi 端编写“DDE Poke”命令处理程序的信息。我没有这方面的演示。我尝试了一下,明显的事情对我来说不太有效(服务器上的项目有一个 OnPoke 事件,我编写了一个简单的客户端,称为 PokeData,但它不起作用)。
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:
TDDEServerItem on your form or data
module.
the server conversation (set
DDEServerItem1.ServerConv=DdeServerConv1
using object inspector, there is a
drop down list, but double clicking
it is enough).
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:
Now save and run your project.
To test it in excel type in:
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).