手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>delphi>列表

Delphi 剪贴板和动态数据交换(四)

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

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; 

DDEClientItemOnChange事件处理过程中把接收到的事件保存在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 小结 

剪贴板和DDEWindows下数据通信的两种方法。Delphi以简便、友好的方式实现了相应的功能,为用户编程提供了方便。一般说来,剪贴板多用于静态数据传输,而DDE用于动态数据交换、控制其它程序运行等场合。这些内容对于多用户环境下的程序开发是很重要的

 

上一篇: Delphi 对象链接与嵌入(一)
下一篇: Delphi 对象链接与嵌入(二)

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!