Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get IDispatch information from a variant property in a Delphi com object in VBA?
    text
    copied!<p>I have a COM object written in Delphi that has a property that returns a variant. Basically this property returns a value depending on the parameter I pass it. When I access the object from VBA (Excel for example), I can write something like :</p> <pre><code>MyObject.MyProperty("IntProperty") = 22 </code></pre> <p>Now the property can also return an IDispatch object, which is stored in the variant. If I access the com object from Delphi, I write the following code to extract that IDispatch information</p> <pre><code>var Info : IMyInterface; Info := IDispatch(TVarData(MyObject.MyProperty['InfoProperty']).VDispatch) as IMyInterface; Info.foo := 10; info.y := 'test'; info.saveit; </code></pre> <p>Is it possible to extract that IDispatch information in VBA? I haven't figured out a way to do it yet.</p> <p>To be 100% clear, the property is of type OLEVariant, and not IDispatch. I have properties that are of type IDispatch, and they work fine.</p> <p>This is the declaration of get_MethodProperty</p> <pre><code>function get_MethodProperty(const aPropertyName: WideString):OLEVariant; </code></pre> <p>It would work if I declared it as</p> <pre><code>function get_MethodProperty(const aPropertyName: WideString):IDispatch; </code></pre> <p>But that is not what I want.</p> <hr/> <p>This is the VBA code, and it fails on the second line</p> <pre><code>Dim Info as Object Set Info = MyObject.MethodProperty("InfoProperty") Info.foo = 10 Info.y = "test" call info.saveit </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload