Getting meaningful info from JIVariant Array

prj123
2012-07-30
2012-11-29
  • prj123

    prj123 - 2012-07-30

    Hi Vikram,

    I am calling a method that looks like this:
    HRESULT Import(BSTR input1, BSTR input2, BSTR input3, BSTR input4,  VARIANT* ids);

    Using J-interop, I'm doing this:

    JIVariant variant = dispatch.callMethodA("Import", new Object {input1, input2, input3, input4});

    The return value variant is an array of length 1. variant.getType returns 8204 which means it is a Variant Array.

    Basically the Import method, adds an entry to a database and returns the database ids of the objects created. What I want to do is call another method in the COM library and access this database entry just created using the database id returned. The second method (for accessing the created entry) takes long as an argument for the database id but the return value I'm getting from the first method (which is "Import") is of type variant array. Would you please be able to tell if I have done something wrong? Or if there is a way of converting from Variant to long?

    All I want to do is to get something meaningful out of the return value i.e. get the database id.

    I have tried to use variant.getObjectAsLong(), as int, as float, as double and as Variant but all of them thrown NullPointerException.

    Also, I am sure that the Import method works correctly as a new entry in the database gets created after calling the method.

    Thank you very much!

     
  • Vikram Roopchand

    Hi,

    can you please show the idl or signature of this method?

    thanks,
    best regards,
    Vikram

     
  • prj123

    prj123 - 2012-08-01

    Hi Vikram,

    Signature of the first method is HRESULT ImportFile ( BSTR xmlFilePath, BSTR customSiteName, BSTR username, BSTR password,  VARIANT *ids);

    And the second method is HRESULT Load ( long siteID, long fixletID, BSTR dbUserName, BSTR password );

    Thank you!

     
  • Vikram Roopchand

    Hi,

    It is a variant , the value being returned is correct. Now if you know what is inside the variant, please call the helper method directly (getXXX) on the variant, if not please examine the "Type" of the Variant and then do the same.

    thanks,
    best regards,
    Vikram

     
  • prj123

    prj123 - 2012-08-10

    Hi again,
    I think I have tried everything in my power but still no success.

    What I'm doing is,
    String xmlFilePath = "something";
    String customSiteName = "something";
    String username = "something";
    String password = "something";

    JIVariant var  = dispatch.callMethodA("ImportFile", new Object { xmlFilePath, customSiteName, username,  password});

    I get the following results:
    var.length = 1
    var.getType() = 8204 (which means it is a variant array)
    var.getFlag() = 64 (not sure what that means)
    var.getObjectAsArray().getUpperBounds() returns an int of length 1 with value 1 in it
    var.getObjectAsArray().getDimensions() returns an value 1 (which means its a 1d array)
    var.getObjectAsXXX where XXX is anything but Array() returns a NullPointerException and var.getObjectAsComObject() returns null.

    I am very new with COM so am I doing something wrong here? Is there a direct way to access the id stored?
    As I said earlier, this function returns database ids which will help me in calling the HRESULT Load ( long siteID, long fixletID, BSTR dbUserName, BSTR password ); by giving me the value of the parameter "fixletID". But I still haven't been able to get the id from the jivariant returned.

    Please help!
    Thank you!

     
  • Vikram Roopchand

    Hi,

    Can you please look at some of the examples (test package in j-interop src) as how to use the JIVariant class. You are unfortunately calling the incorrect methods.

    thanks,
    best regards,
    Vikram

     
  • prj123

    prj123 - 2012-08-10

    Ok will do. Thanks for the quick reply!

     
  • prj123

    prj123 - 2012-08-10

    Finally, got it. All I needed to do was

    JIArray a=var.getObjectAsArray();
    Object b =(Object)a.getArrayInstance();
    System.out.println("ID is" + ((JIVariant)b).getObjectAsUnsigned().getValue());

    Thank you very much for your help! Very much appreciated!

     

Log in to post a comment.