IConnectPoint、IConnectPointContainer、EventSink是什么东西?
解决方案 »
- 如何输出字符串的十六进制码
- dll的DBGrid问题 出现 control ‘rzPageControl1’has no parent windows
- 如何如何分割*.CSV文件?
- 如何测试一个文件已经不再增长?谢了!
- 用CreateOLEObject建立了一个WordApp后如何监视Word是否关闭了
- 物归原主,散分5000,一天后结贴,no.7
- 有谁知道paradox数据表的相关信息?如字段类型,索引,数据查找等等?
- 为什么系统会提示“table is not indexed”?
- delphi XE5 编译的APK启动时短暂黑屏,如何解决?
- SOS 神啊,救救我吧
- delphi下用mscomm接收二进制数组的问题
- 问一个关于数据库的蠢问题
当只有一个Client时可以正常响应这个事件(跨进程的事件响应是实现了)。
但是当我运行另一个Client时他会创建一个新的Sever,
而不是响应原来那个Sever的事件!快点帮帮我!
unit EventTestIMPL2;(Sever)interfaceuses
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;implementationuses 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;interfaceuses
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.
这对CSDN来说是个不光荣的消息——答案来自大富翁的高手们!
看看这个例子,也许我就不用进一步解释了。
http://www.netdrive.com/MyDrive/get.jsp/%7Eoldpeasant/My%20Public%20Files/ChatServer.zip
问题的关键是要循环触发多个客户的事件。