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