Convert OleVariant to Object in Delphi

前端 未结 2 1002
我寻月下人不归
我寻月下人不归 2020-12-20 04:44

I\'m working on this project where we don\'t have the source code for large chunks of the project, but we have the .DLL files with some information. There is a bug in the D

相关标签:
2条回答
  • 2020-12-20 05:25

    Try type cast to IUnknown first.

    tempSubclass := Subclass(ParentClass(Integer(IUnknown(oleVariantCast))));
    
    0 讨论(0)
  • 2020-12-20 05:50

    A Dispatch Variant is a pretty generic interface, not a class (which is why it can't be typecast to a Delphi object - it isn't one, and doesn't have the VMT for the class you're trying to cast it to become).

    If the DLL contains a type library, you can import that into Delphi and then use the interfaces it contains directly without trying to cast them to anything else first.

    If you have documentation about the actual interface implementation in the DLL, you can write a Delphi class that uses that interface. You can convert it by defining a type to represent the interface, and then get access to it using as:

    type
      TYourInterface=interface(IDispatch)
        // the interface definition here
      end;
    
    var
      Intf: TYourInterface;
    begin
      Intf := YuorOleVariant as TYourInterface;
      // work with interface from DLL using Intf.
      Intf := nil;
    end;
    
    0 讨论(0)
提交回复
热议问题