IConnectPoint、IConnectPointContainer、EventSink是什么东西?

解决方案 »

  1.   

    我已经在Automation Object中添加了一个事件,
    当只有一个Client时可以正常响应这个事件(跨进程的事件响应是实现了)。
    但是当我运行另一个Client时他会创建一个新的Sever,
    而不是响应原来那个Sever的事件!快点帮帮我!
      

  2.   

    顺便把我的源码贴上
    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.
      

  3.   

    很遗憾!我不得不自己结束这个问题。
    这对CSDN来说是个不光荣的消息——答案来自大富翁的高手们!
    看看这个例子,也许我就不用进一步解释了。
    http://www.netdrive.com/MyDrive/get.jsp/%7Eoldpeasant/My%20Public%20Files/ChatServer.zip
    问题的关键是要循环触发多个客户的事件。