B
berg
Unregistered / Unconfirmed
GUEST, unregistred user!
为什么我的dde不能从server向client发信息呢?
前一段时间提了这个问题可没有人回答,我查了以前的帖子看到你们讨论过这样的问题
解决了吗?给小弟解释一下,最好能给个例子看看,不胜感激!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=811375
client:如下
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, DdeMan;
type
TForm2 = class(TForm)
DdeClientConv1: TDdeClientConv;
DdeClientItem1: TDdeClientItem;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure DdeClientItem1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
// DdeClientItem1.DdeConv:=DdeClientConv1;
//ddeclientconv1.connectmode:=ddeuserual;
// DdeClientConv1.SetLink('Project1','DdeServerConv1');
// if not DdeClientConv1.SetLink('Project1', 'DdeServerConv1') then
// raise Exception.Create ('Could not link to DDE server.');
// DdeClientItem1.DdeItem:='DdeServerItem1'; // 指定DDE项目
// ddeclientconv1.OpenLink;
end;
procedure TForm2.DdeClientItem1Change(Sender: TObject);
begin
// 响应DDE服务器端数据的改变:
Edit2.Text:=DdeClientItem1.Text;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
DdeClientConv1.PokeDataLines(DdeClientItem1.DdeItem, Memo1.Lines);
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
DdeClientItem1.DdeConv:=DdeClientConv1;
// 设置链接,指定DDE服务:
DdeClientConv1.SetLink('Project1','DdeServerConv1');
if not DdeClientConv1.SetLink('Project1', 'DdeServerConv1') then
raise Exception.Create ('Could not link to DDE server.');
// ddeclientconv1.DdeService:='project1'; //程序名
//ddeclientconv1.DdeTopic:='ddeserverconv1'; //主题
DdeClientItem1.DdeItem:='DdeServerItem1'; // 指定DDE项目名
ddeclientconv1.OpenLink;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DdeClientConv1.CloseLink(); // 关闭链接
end;
end.
server如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, DdeMan;
type
TForm1 = class(TForm)
DdeServerConv1: TDdeServerConv;
DdeServerItem1: TDdeServerItem;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
procedure Edit1Change(Sender: TObject);
procedure DdeServerItem1PokeData(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Edit1Change(Sender: TObject);
begin
// 将Edit1组件中的内容发送向客户机端
DdeServerItem1.Text:=Edit1.Text;
end;
procedure TForm1.DdeServerItem1PokeData(Sender: TObject);
begin
// 根据回传数据改变Edit2组件中的显示内容
Edit2.Text:=DdeServerItem1.Lines.Strings[0];
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
application.Terminate;
end;
end.
当我把打开连接放在窗体的创建事件( TForm2.FormCreate(Sender: TObject);)
中时就一切正常?而放在按钮事件中就不能从server向client发信息,只能从client
向server回传信息,
请帮小弟看看是 什么原因?多谢了!
可以连同我上次的分一起拿去!
前一段时间提了这个问题可没有人回答,我查了以前的帖子看到你们讨论过这样的问题
解决了吗?给小弟解释一下,最好能给个例子看看,不胜感激!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=811375
client:如下
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, DdeMan;
type
TForm2 = class(TForm)
DdeClientConv1: TDdeClientConv;
DdeClientItem1: TDdeClientItem;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure DdeClientItem1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
// DdeClientItem1.DdeConv:=DdeClientConv1;
//ddeclientconv1.connectmode:=ddeuserual;
// DdeClientConv1.SetLink('Project1','DdeServerConv1');
// if not DdeClientConv1.SetLink('Project1', 'DdeServerConv1') then
// raise Exception.Create ('Could not link to DDE server.');
// DdeClientItem1.DdeItem:='DdeServerItem1'; // 指定DDE项目
// ddeclientconv1.OpenLink;
end;
procedure TForm2.DdeClientItem1Change(Sender: TObject);
begin
// 响应DDE服务器端数据的改变:
Edit2.Text:=DdeClientItem1.Text;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
DdeClientConv1.PokeDataLines(DdeClientItem1.DdeItem, Memo1.Lines);
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
DdeClientItem1.DdeConv:=DdeClientConv1;
// 设置链接,指定DDE服务:
DdeClientConv1.SetLink('Project1','DdeServerConv1');
if not DdeClientConv1.SetLink('Project1', 'DdeServerConv1') then
raise Exception.Create ('Could not link to DDE server.');
// ddeclientconv1.DdeService:='project1'; //程序名
//ddeclientconv1.DdeTopic:='ddeserverconv1'; //主题
DdeClientItem1.DdeItem:='DdeServerItem1'; // 指定DDE项目名
ddeclientconv1.OpenLink;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DdeClientConv1.CloseLink(); // 关闭链接
end;
end.
server如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, DdeMan;
type
TForm1 = class(TForm)
DdeServerConv1: TDdeServerConv;
DdeServerItem1: TDdeServerItem;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
procedure Edit1Change(Sender: TObject);
procedure DdeServerItem1PokeData(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Edit1Change(Sender: TObject);
begin
// 将Edit1组件中的内容发送向客户机端
DdeServerItem1.Text:=Edit1.Text;
end;
procedure TForm1.DdeServerItem1PokeData(Sender: TObject);
begin
// 根据回传数据改变Edit2组件中的显示内容
Edit2.Text:=DdeServerItem1.Lines.Strings[0];
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
application.Terminate;
end;
end.
当我把打开连接放在窗体的创建事件( TForm2.FormCreate(Sender: TObject);)
中时就一切正常?而放在按钮事件中就不能从server向client发信息,只能从client
向server回传信息,
请帮小弟看看是 什么原因?多谢了!
可以连同我上次的分一起拿去!