Delphi CreateOleObject事件 [英] Delphi CreateOleObject events
本文介绍了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.
- 创建一个新的对象(类)一个href =http://docwiki.embarcadero.com/VCL/en/System.TInterfacedObject =noreferrer>
TInterfacedObject
实现
IDispatch
- 实现新类的
Invoke()
函数 - 查询连接点容器(
IConnectionpointContainer
)和所需的连接点。 - 使用
IConnectionPointContainer.FindConnectionPoint
- 终于执行
IConnectionPoint.Advise()
usin你实现
$IDispatch
- 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
-
如何使用使用createoleobject创建的对象事件 -
Delphi 5运行powerpoint(使用具有事件的晚绑定对象的示例) - Delphi 5运行powerpoint (使用具有事件的晚期绑定对象的示例)
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)
尝试这些链接以获取有关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屋!
查看全文