Forum Discussion

bwehking's avatar
bwehking
Occasional Contributor
8 years ago

Read array of strings from dotNet (CLR Bridge)

Hello,

 

I guess I miss something obvious:

 

I'm using TestComplete 12.31.1833.7. I use the CLR Bridge to call a .NET method which returns an array of strings.

The documentation says that "single-dimensional .NET arrays" have an OleValue property, which allows to access the array members. But how do I access the members? The debugger only gives me "undefined" values. To better diagnose the issue, I even hardcoded the members of the string array on the .NET side.

 

Do you have any ideas?

Thanks in advance!

 

Bernd

 

  • Hi Bernd,

     

    Try the Array.Get method:

    functions.Get(0)
  • Hello,

     

    thank you for pointing me in the right direction! But that means, that the documentation is wrong:

    Single-dimensional arrays have to be accessed without using OleValue and the array elements need to be addressed using Get(), as it is stated for multi-dimensional arrays.

     

    This worked:

    var justTrying = Config.myConfig.get_ArrayForTestComplete();
    var first = justTrying.Get(0);

    I guess, the documentation should be reviewed.

     

    Thank you!

     

    Bernd

     

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Bernd,

     

    Try the Array.Get method:

    functions.Get(0)
    • bwehking's avatar
      bwehking
      Occasional Contributor

      Hello,

       

      thank you for pointing me in the right direction! But that means, that the documentation is wrong:

      Single-dimensional arrays have to be accessed without using OleValue and the array elements need to be addressed using Get(), as it is stated for multi-dimensional arrays.

       

      This worked:

      var justTrying = Config.myConfig.get_ArrayForTestComplete();
      var first = justTrying.Get(0);

      I guess, the documentation should be reviewed.

       

      Thank you!

       

      Bernd

       

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        Hi Bernd,

         

        A quick update: The behavior on your screenshot seems to be specific to JScript. JScript's native array format differs from the array format used by other scripting languages and returned by OleValue. Because of this, the OleValue array needs to be converted to the JScript array format using .toArray():

        var justTrying = Config.myConfig.get_ArrayForTestComplete()
        justTrying = justTrying.OleValue.toArray();
        // Now you can see the "justTrying" array items in the Locals panel
        // and access the array items using []
        var first = justTrying[0];

        We'll update the docs to better explain .NET array usage.

         

        Thanks for your feedback!