在Delphi中将OleVariant转换为Object [英] Convert OleVariant to Object in Delphi

查看:193
本文介绍了在Delphi中将OleVariant转换为Object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在这个项目中,我们没有大块的项目的源代码,但我们有.DLL文件的一些信息。 DLL文件中有一个错误。我能够创建一个类的子类与其中的错误,我想downcast已经存在的对象,我已经访问它的一个点。问题是,在任何时候,我有权访问对象,它被转换为一个变体。我试过下面的(编辑删除上下文):

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 DLL files. I am able to create a subclass of the class with the bug in it and I would like to downcast the object which already exists at a point I have access to it. The issue is that at any point I have access to the object, it's cast as a Variant. I've tried the following (edited to remove context):

tempSubclass := Subclass(ParentClass(Integer(oleVariantCast)));

但我得到以下错误:

Could not convert variant of type (Dispatch) into type (Integer)

有没有其他方法可以获得指向OleVariant对象的指针和/或进行类型转换?

Is there any other way to get the pointer to the object out of the OleVariant and/or do the typecasting involved?

谢谢。

编辑:是的,Parentclass实现IDispatch。
CORRECTION:父类实现从IDispatch继承的接口。

Yes, the Parentclass implements IDispatch. CORRECTION: The parentclass implements an interface which inherits from IDispatch.

推荐答案

尝试类型强制转换为IUnknown。 p>

Try type cast to IUnknown first.

tempSubclass := Subclass(ParentClass(Integer(IUnknown(oleVariantCast))));

这篇关于在Delphi中将OleVariant转换为Object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆