setParameter for an array property with JACOB

佐手、 提交于 2019-12-12 04:44:22

问题


I have the following VB code :

Set QuoteRequest = Quotes.Add
With QuoteRequest
    .No = 1
    .QuoteCode(0)="101"
    .Code(0)="NAME1"
    .Code(1)="NAME2"
End With

I use JACOB to access that COM object.

quoteRequest.setProperty("No",1);
quoteRequest.setProperty("QuoteCode(0)","101");
quoteRequest.setProperty("Code(0)", "NAME1");
quoteRequest.setProperty("Code(1)", "NAME2");

But this leads to exception

com.jacob.com.ComFailException: Can't map to dispid: QuoteCode(0)

How can I pass that property?


回答1:


import com.jacob.com.*;
import com.jacob.activeX.*;

static void setProperty(Dispatch d, String sName, String sIndex, String sValue) {
  Variant av[] = { new Variant(sIndex), new Variant(sValue) };
  Dispatch.invokev(d, sName, Dispatch.Put, av, NO_INT_ARGS).safeRelease();
  av[0].safeRelease(); av[1].safeRelease();
  }

That's the code I used. Works for me, however I was doing some changes to Jacob, to force garbaging of unused variants. Hard to say what I exactly did, it was years ago :)



来源:https://stackoverflow.com/questions/39871675/setparameter-for-an-array-property-with-jacob

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