Delphi CreateOleObject事件 [英] Delphi CreateOleObject events

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

问题描述

有一个代码:

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

此COM对象具有事件(例如OnClick)。如何连接到这些事件而不导入TLB?

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天全站免登陆