Delphi CreateOleObject events

送分小仙女□ 提交于 2019-12-30 07:10:28

问题


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?


回答1:


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 implements IDispatch
  • 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 the IDispatch

you can found examples of this implementation on these links

  • How to use an objects event created using createoleobject
  • Delphi 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

  • Automation in Delphi COM Programming
  • Supporting automation events in Delphi


来源:https://stackoverflow.com/questions/3643463/delphi-createoleobject-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!