begin
DDEClient.SetLink (AppName.Text, TopicName.Text);
DDEClientItem.DdeConv := DDEClient;
DDEClientItem.DDEItem := ItemName.Text;
end;
通过从剪贴板粘贴联接信息来建立联接的实现代码如下。
procedure TFormD.Edit1Click(Sender: TObject);
var
Service, Topic, Item : String;
begin
PasteLink1.Enabled := GetPasteLinkInfo (Service, Topic, Item);
end;
procedure TFormD.doPasteLink(Sender: TObject);
var
Service, Topic, Item : String;
begin
if GetPasteLinkInfo (Service, Topic, Item) then
begin
AppName.Text := Service;
TopicName.Text := Topic;
ItemName.Text := Item;
DDEClient.SetLink (Service, Topic);
DDEClientItem.DdeConv := DDEClient;
DDEClientItem.DdeItem := ItemName.Text;
end;
end;
在
DDEClientItem的OnChange事件处理过程中把接收到的事件保存在DDEDat中。procedure TFormD.DDEClientItemChange(Sender: TObject);
begin
DDEDat.Lines := DDEClientItem.Lines;
end;
数据发送的实现代码如下。
procedure TFormD.doPoke (Sender: TObject);
var
DDECli : TDDEClientConv;
begin
DDECli := DDEClientItem.DdeConv;
if DdeCli <> nil then
DDECli.PokeDataLines (DDEClientItem.DDEItem, PokeDat.Lines);
end;
宏指令发送的实现代码如下。
procedure TFormD.doMacro (Sender: TObject);
var
DDECli: TDDEClientConv;
Cmd: String;
begin
DDECli := DDEClientItem.DdeConv;
if DDECli <> nil then
begin
Cmd := PokeDat.Text #13#10;
DDECli.ExecuteMacroLines (PokeDat.Lines, True);
end;
end;
运行以上两个程序,建立DDE联接。经测试,数据传输、数据发送和宏指令的发送与执行都达到预期要求。
7.4.4 小结
剪贴板和DDE是Windows下数据通信的两种方法。Delphi以简便、友好的方式实现了相应的功能,为用户编程提供了方便。一般说来,剪贴板多用于静态数据传输,而DDE用于动态数据交换、控制其它程序运行等场合。这些内容对于多用户环境下的程序开发是很重要的
上一篇: Delphi 对象链接与嵌入(一)
下一篇: Delphi 对象链接与嵌入(二)
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




