How to cast OleVariant to IDispatch derived?

醉酒当歌 提交于 2019-12-20 04:07:35

问题


I bring today another question that is burning my head,

I do import a DAO 3.6 type library to my delphi 7, and I start to see many interesting intefaces so I face on intriguing question.

Every time the class Fields appears on property of another class, they have the right definition, I mean, he is defined as Fields, but in Index class, in the parts where he describes all fields participants of his structure, the property fields appears not as Fields, but as OleVariant.

Look at the diference from TableDefs, that have Fields property to and compare to Index definition:

_TableDef = interface(_DAO)
...
property Fields: Fields read Get_Fields;
...
end;

_Index = interface(_DAO)
...
property Fields: OleVariant read Get_Fields write Set_Fields;
...
end;

The question is, is there a way to cast that Fields that appears like OleVariant type to be casted on Fields interface type?

I´m very gratefull for all that every help me here in StackOverflow


回答1:


If I understand your question correctly, you are asking how to convert a variant to an IDispatch. Do that like this:

IDispatch(V)

In your case I think you have another type, Fields that derives from IDispatch. You can get hold of that like this:

IDispatch(V) as Fields


来源:https://stackoverflow.com/questions/16111060/how-to-cast-olevariant-to-idispatch-derived

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!