Delphi的CreateOleObject事件 [英] Delphi CreateOleObject events
本文介绍了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.
- 创建一个新对象a href =http://docwiki.embarcadero.com/VCL/en/System.TInterfacedObject =nofollow noreferrer>
TInterfacedObject
b $ bIDispatch
- 实施您的新的
Invoke()
- 查询连接点容器(
- 使用
=http://msdn.microsoft.com/en-us/library/ms692476%28VS.85%29.aspx =nofollow noreferrer>IConnectionPointContainer.FindConnectionPoint
- 最后执行
IDispatch $>,可以使用$ aspxrel =nofollow noreferrer>
IConnectionPoint.Advise()
c $ c>
- 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)
尝试这些链接,了解有关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屋!
查看全文