user2092868
user2092868

Reputation: 273

How to cast OleVariant to IDispatch derived?

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

Upvotes: 1

Views: 2506

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

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

Upvotes: 6

Related Questions