获取 IDispatch 接口成员的访问权限
我是一名物理学家。我正在尝试使用导入的 ActiveX 控件(ocx 文件)在 Delphi 上工作。假设库中有 3 个自动化接口:IGraph、IGraphAxes 和 IAxis。库的结构如下:
===IGraph 的属性:===
Idispatch* IGraphAxes;
... //其他成员
===IGraphAxes 的属性:===
Idispatch* XAxis;
Idispatch* YAxis;
Idispatch* ZAxis;
整数颜色;
整数样式;
… //其他成员
===IAxis 属性:===
浮动最小值、最大值;
布尔显示编号;
... //其他成员
从 IGraph 中,我可以使用 GetIDsOfNames() 和 Invoke() 函数访问 IGraphAxes 的简单成员(颜色和样式)。但是当我尝试访问 XAxis(或 YAxis、Zaxis)时,它会生成错误。首先,我使用 GetIDsOfNames(),它返回 XAxis 的 dispid,没有任何问题。但是,当我使用该 dispid 调用 Invoke 时,会出现错误“地址访问冲突......”。看起来,idispatch 指针 (**Xaxis)* 没有指向任何内容。我该如何解决这个问题?制作方法
Idispatch* Xaxis
和
IAxis接口相互连接?
PS 抱歉我的英语,我不是母语人士
I am a physicist. I am trying to work on Delphi with an imported activex control (ocx file). Let’s say there are 3 automation interfaces in the library: IGraph, IGraphAxes and IAxis. The structure of the library is such that:
===IGraph’s properties:===
Idispatch* IGraphAxes;
... //other members
===IGraphAxes’ properties:===
Idispatch* XAxis;
Idispatch* YAxis;
Idispatch* ZAxis;
integer Color;
integer Style;
… //other members
===IAxis properties:===
float Min, Max;
Boolean ShowNumbers;
… //other members
From IGraph, I am able to get an access to simple members of IGraphAxes (Color and Style) using GetIDsOfNames() and Invoke() functions. But when I try to get an access to XAxis (or YAxis, Zaxis) it generates an error. First, I use GetIDsOfNames() and it returns the dispid of XAxis without any problem. But when I call Invoke with that dispid there is an error “Access violation at address …”. It seems, the idispatch pointer (**Xaxis)* points to nothing. How can I solve this? How to make
Idispatch* Xaxis
and
IAxis interface attached to each other?
P.S. sorry for my english, i am not a native speaker
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Delphi 内置了对 IDispatch 后期绑定的支持,因此您不需要直接调用 Invoke()。只需像普通属性一样访问成员,Delphi 就会在幕后为您调用 Invoke()。
如果您想直接调用 Invoke(),请显示失败的实际代码。 AV 很可能是由于您的代码中的错误而不是 OCX 本身的错误造成的。
Delphi has built-in support for IDispatch late binding, so you do not need to call Invoke() directly. Just access the members like normal properties, and Delphi will call Invoke() behind the scenes for you.
If you want to call Invoke() directly, then please show your actual code that is failing. An AV is likely due to a bug in your code rather than in the OCX itself.
当我将 ocx 文件导入 Delphi 时,它出现在 Component Palette 的 ActiveX 选项卡上。我只需用鼠标拖动它并放置一个表单和一个对象
图1:TGraph;
自动添加到我的代码中。它的属性和事件在对象检查器窗口中变得可见。现在我想从我的代码中访问控件的轴。正如您所看到的,该属性代表坐标轴。另外我猜测 IGraphAxes 的 XAxis/YAxis/ZAxis 成员是 IGraphAxis 类型的 idispatch 指针。我编写了以下过程来访问 idispatch 接口:
它们与 IGraphAxes 的 Color 和 Style 属性配合良好:
或者
但是如何获得对 IGraphAxes 的 XAxis/YAxis/ZAxis 成员的完全访问权限?
When I import the ocx file into Delphi, it appears on the ActiveX tab of the Component Palette. I just drag it with mouse and put on a form and an object
Graph1: TGraph;
is automatically added to my code. Its properties and events become visible in the Object Inspector window. Now I want to get an access to the control’s axes from my code. As you can see, the property represents coordinate axes. Also I guess that IGraphAxes’ XAxis/YAxis/ZAxis members are idispatch pointers of type IGraphAxis. I wrote the following procedures to access an idispatch interface:
They work fine with Color and Style properties of IGraphAxes:
Or
But how to get full access to XAxis/YAxis/ZAxis members of IGraphAxes?
感谢您的回复。
实际上,activex 控件是一个用于绘制一些 3D 图形的第三方可视化组件。
以下是activex库的内容:
Thanks for your reply.
Actually the activex control is a third-party visual component for plotting some 3d graphics.
Here is the contents of the activex library:
这是从类型库生成的单元文件。
单元GraphLib_TLB;
And here is the unit file generated from the type library.
unit GraphLib_TLB;