简体   繁体   中英

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. 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:

(SomeOcxObject as IPersistStreamInit).InitNew;

or go the long way round and call QueryInterface yourself:

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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