of course you can,
adding the event support when you create Com server, and create some method for this
event interface, when server want to ask clientdo
some thing, just invoke this method.
in cilent side, add the code below
TEventSink = class(TInterfacedObject, IUnknown,IDispatch)
private
FController: tfm_Snap;
{IUknown methods}
function QueryInterface(const IID: TGUID;
out Obj):HResult;stdcall;
{Idispatch}
function GetTypeInfoCount(out Count: Integer): HResult;
stdcall;
function GetTypeInfo(Index, LocaleID: Integer;
out TypeInfo): HResult;
stdcall;
function GetIDsOfNames(const IID: TGUID;
Names: Pointer;
NameCount, LocaleID: Integer;
DispIDs: Pointer): HResult;
stdcall;
function Invoke(DispID: Integer;
const IID: TGUID;
LocaleID: Integer;
Flags: Word;
var Params;
VarResult, ExcepInfo, ArgErr: Pointer): HResult;
stdcall;
public
constructor Create(Controller: Tfm_Snap);
end;
function TEventSink.QueryInterface(const IID: TGUID;
out Obj):HResult;stdcall;
begin
if GetInterFace(IID,Obj) then
Result := S_OK
else
if IsEqualIID(IID,IMonCliEvents) then
Result := QueryInterface(IDispatch,Obj)
else
Result := E_NOINTERFACE;
end;
function TEventSink.Invoke(DispID: integer;
const IID: TGUID;
LocaleID: integer;
Flags: Word;
var Params;
VarResult,ExcepInfo,ArgErr
ointer): HResult;
begin
Result := S_OK;
case DispID of
1: begin
ParamCount := DispParams.cArgs;
if ParamCount>0 then
begin
ParamData:=OleVariant(DispParams.rgvarg^[0]) ;
//do something here
end;
end;
end;
end;
constructor TEventSink.Create(Controller: tfm_Snap);
begin
inherited Create;
FController := Controller;
end;
function TEventSink.GetTypeInfoCount(out Count: Integer): HResult;
begin
Result := S_OK;
end;
function TEventSink.GetTypeInfo(Index, LocaleID: Integer;
out TypeInfo): HResult;
begin
Result := S_OK;
end;
function TEventSink.GetIDsOfNames(const IID: TGUID;
Names: Pointer;
NameCount, LocaleID: Integer;
DispIDs: Pointer): HResult;
begin
Result := S_OK;
end;