简体   繁体   English

如何从 COM 控件获取 Delphi 中的非默认接口?

[英]How to get non-default interfaces in Delphi from a COM control?

I have imported a OCX control to Delphi, it shows the TLB and OCX classes.我已经将一个 OCX 控件导入到 Delphi,它显示了 TLB 和 OCX 类。 It works fine but I only can access to default interface.它工作正常,但我只能访问默认界面。

How can I access to other interfaces?如何访问其他接口?

You can either use the as operator on a instance reference, eg:您可以在实例引用上使用as运算符,例如:

(SomeOcxObject as IPersistStreamInit).InitNew;

or go the long way round and call QueryInterface yourself:或者走很长的路,自己调用QueryInterface

var
  x:IPersistStreamInit;
begin
  if SomeOcxObject.QueryInterface(IPersistStreamInit,x)<>S_OK then
    RaiseLastOSError;
  x.InitNew;

(I'm just using IPersistStreamInit here as an example, you didn't specify which interface you'd be using.) (我只是在这里使用IPersistStreamInit作为示例,您没有指定要使用的接口。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM