Delphi CreateOleObject events
-
30-09-2019 - |
Question
There is a code:
var
myobject: OleVariant;
begin
myobject := CreateOleObject('SomeNamespace.SomeClass');
end;
This COM object has events (for example OnClick). How should I connect to these events without importing TLB?
Solution
You are working with COM late-binding, so do you need write a lot of code to handle events. this task is not difficult if you know COM, basically do you need follow these steps.
- Create a new object(class) derived from
TInterfacedObject
that implementsIDispatch
- implement the
Invoke()
function of your new class - Query for the connection point container (
IConnectionpointContainer
) and desired connection point. - sink the connection point using
IConnectionPointContainer.FindConnectionPoint
- finally execute the
IConnectionPoint.Advise()
using your implementation of theIDispatch
you can found examples of this implementation on these links
How to use an objects event created using createoleobjectDelphi 5 running powerpoint (example using a late binding object with events)- Delphi 5 running powerpoint (example using a late binding object with events)
try out these links for more info about COM, late-binding and events
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow