type
TEventSink = class(TAutoObject, IEventSink)
protected
function onclick(const dispSource: IDispatch): WordBool; safecall;
{ Protected declarations }
public
function ObjQueryInterface(const IID: TGUID; out Obj): HResult; override; stdcall;
end;
implementation
uses ComServ, u_Main, Windows;
function TEventSink.ObjQueryInterface(const IID: TGUID; out Obj): HResult;
begin
if IsEqualGUID(IID, Form1.FEventIID) and GetInterface(IDispatch, Obj) then
Result := S_OK
else
Result := inherited ObjQueryInterface(IID, Obj);
end;
function TEventSink.onclick(const dispSource: IDispatch): WordBool;
begin
OleVariant(dispSource).srcElement.style.backgroundColor := '#' + IntToHex(RGB(Random(256), Random(256), Random(256)), 6);
Result := True;
end;
CoEventSink = class
class function Create: IEventSink;
class function CreateRemote(const MachineName: string): IEventSink;
end;
implementation
uses ComObj;
class function CoEventSink.Create: IEventSink;
begin
Result := CreateComObject(CLASS_EventSink) as IEventSink;
end;
class function CoEventSink.CreateRemote(const MachineName: string): IEventSink;
begin
Result := CreateRemoteComObject(MachineName, CLASS_EventSink) as IEventSink;
end;
function TEventSink.ObjQueryInterface(const IID: TGUID; out Obj): HResult;
begin
if IsEqualGUID(IID, Form1.OleEventIID) and GetInterface(IDispatch, Obj) then
Result := S_OK
else
Result := inherited ObjQueryInterface(IID, Obj);
end;
procedure TEventSink.OnClear;
begin
Form1.Memo1.Clear;
end;
procedure TEventSink.OnTextChanged(const NewText: WideString);
begin
Form1.Memo1.Text := NewText;
end;