谁能告诉我在COM/DLL中事件派发与(跨进程)响应的机制

jifee 2000-08-11 03:08:00
我在DLL中有一个AutoObject,加入了一个IXXEvents事件支持接口,我希望在这个Sever中派发一个事件,并在若干个Client中响应(Client与Sever可能不在同一个进程中)。希望与各位高手成为朋友。
...全文
169 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jifee 2000-09-04
  • 打赏
  • 举报
回复
很遗憾!我不得不自己结束这个问题。
这对CSDN来说是个不光荣的消息——答案来自大富翁的高手们!
看看这个例子,也许我就不用进一步解释了。
http://www.netdrive.com/MyDrive/get.jsp/%7Eoldpeasant/My%20Public%20Files/ChatServer.zip
问题的关键是要循环触发多个客户的事件。
jifee 2000-08-21
  • 打赏
  • 举报
回复
自问自答不是个办法!到底有没有高手,给我指条明路吧!
jifee 2000-08-18
  • 打赏
  • 举报
回复
顺便把我的源码贴上
unit EventTestIMPL2;(Sever)

interface

uses
ComObj, ActiveX, AxCtrls, Classes, EventTest2_TLB, StdVcl;

type
TMYOB2 = class(TAutoObject, IConnectionPointContainer, IMYOB2)
private
{ Private declarations }
FConnectionPoints: TConnectionPoints;
FConnectionPoint: TConnectionPoint;
FSinkList: TList;
FEvents: IMYOB2Events;
procedure ValueChangeEvent(Sender: TObject);
public
procedure Initialize; override;
protected
{ Protected declarations }
property ConnectionPoints: TConnectionPoints read FConnectionPoints
implements IConnectionPointContainer;
procedure EventSinkChanged(const EventSink: IUnknown); override;
function Get_Value: Integer; safecall;
procedure Set_Value(Value: Integer); safecall;
end;

implementation

uses ComServ,SeverForm;

procedure TMYOB2.EventSinkChanged(const EventSink: IUnknown);
begin
FEvents := EventSink as IMYOB2Events;
if FConnectionPoint <> nil then
FSinkList := FConnectionPoint.SinkList;
end;

procedure TMYOB2.Initialize;
begin
inherited Initialize;
FConnectionPoints := TConnectionPoints.Create(Self);
if AutoFactory.EventTypeInfo <> nil then
FConnectionPoint := FConnectionPoints.CreateConnectionPoint(
AutoFactory.EventIID, ckSingle, EventConnect)
else FConnectionPoint := nil;

FormSever:=TFormSever.Create(Nil);
FormSever.Show;
FormSever.SpinEdit1.OnChange:=ValueChangeEvent;
end;


function TMyOB2.Get_Value: Integer;
begin
Result:=FormSever.SpinEdit1.Value;
end;

procedure TMyOB2.Set_Value(Value: Integer);
begin
FormSever.SpinEdit1.Value:=Value;
end;

procedure TMyOB2.ValueChangeEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.ValueChanged;
end;

initialization
TAutoObjectFactory.Create(ComServer, TMYOB2, Class_MYOB2,
ciSingleInstance, tmApartment);
end.unit ClienForm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,EventTest2_TLB;

type
TFormClient = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Procedure SeverEvent(Sender:TObject);
end;

var
FormClient: TFormClient;
MyOB:IMyOB2;
MyOBT:TMyOB2;

implementation

{$R *.DFM}


procedure TFormClient.FormCreate(Sender: TObject);
begin
MyOB:=CoMyOB2.Create As IMyOB2;
MyOBT:=TMyOB2.Create(Self);
MyOBT.Connect;
MyOBT.OnValueChanged:=FormClient.SeverEvent;
end;

procedure TFormClient.SeverEvent(Sender: TObject);
begin
FormClient.Edit1.Text:=IntToStr(MyOBT.Value);
end;

procedure TFormClient.Button1Click(Sender: TObject);
begin
MyOBT.Value:=100;
// MyOB.Value:=100;
end;

end.

jifee 2000-08-18
  • 打赏
  • 举报
回复
我已经在Automation Object中添加了一个事件,
当只有一个Client时可以正常响应这个事件(跨进程的事件响应是实现了)。
但是当我运行另一个Client时他会创建一个新的Sever,
而不是响应原来那个Sever的事件!快点帮帮我!
jifee 2000-08-15
  • 打赏
  • 举报
回复
IConnectPoint、IConnectPointContainer、EventSink是什么东西?

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧