Delphi的CreateOleObject事件 [英] Delphi CreateOleObject events

查看:809
本文介绍了Delphi的CreateOleObject事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个代码:

var 
myobject: OleVariant;
begin
 myobject := CreateOleObject('SomeNamespace.SomeClass');
end;

此COM对象有事件(例如OnClick)。

This COM object has events (for example OnClick). How should I connect to these events without importing TLB?

推荐答案

您正在使用COM后期绑定,因此您需要写入很多代码来处理事件。这个任务并不困难,如果你知道COM,基本上你需要按照这些步骤。

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)

尝试这些链接,了解有关COM,延迟绑定和事件的更多信息

try out these links for more info about COM, late-binding and events

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

这篇关于Delphi的CreateOleObject事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆