Taking the HTMLElementEvents2 interface in MSHTML as an example, each of the EventMethods is passed a pEvtObj parameter, as in
HTMLElementEvents2 = dispinterface
[...]
function onclick(const pEvtObj: IHTMLEventObj): WordBool; dispid -600;
to identify which element called the event. So, if you define a class descended from TInterfacedObject which implements the HTMLElementEvents2 interface, in the implemented event methods, you could identify which particular HTML element called the event handler, and so access its members.
Being able to identify the caller object which invoked the event is pretty much essential where your handler instance is receiving event calls from multiple callers (e.g. when the handler is attached to multiple HTML elements in the MSHTML example).
This method of implementing a COM Events handler works fine, but is a bit verbose in source terms because it requires defining methods which implement each of the events in the event interface.
There is an alternative, much more concise, method for implementing an event handler, based I assume on the TEventDispatch class in OleCtrls.Pas, which allows you to attach a handler to a single event - see my answer to the q Detect when the active element in a TWebBrowser document changes.
The problem with the technique in that answer is that I can't see a way inside the Invoke implementation to identify the caller object, and my questions is, can this be done and if so, how?
I've tried observing the untyped Params argument passed to the answer's Invoke, by code like this:
function TEventObject.Invoke(DispID: Integer; const IID: TGUID;
LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo,
ArgErr: Pointer): HResult;
var
vPDispParams : PDispParams;
begin
vPDispParams := PDispParams(@Params);
[...]
but the rgvarg member of vPDispParams^ (which I was hoping to contain the pEvtObj parameter) contains no elements, and its cArgs is zero.
The code in my answer to the linked q is an MCVE of what I'm asking.