Tsachi Nimni was kind enough to publish what I think is an undocumented killer feature in QTP’s Java-Addin – an inherent capability to use Java arrays.
When working with Java object properties, you’re bound to come across a property which stores its data in an array. Unlike .Net or VB arrays, Java arrays are completely inaccessible to VBScript, and it you’ll try to access the array’s inner items, you’ll fail.
Luckily. the method Tsachi suggests provides an effective workaround. Here’s a quick sample he provides:
'Just an example for getting a Java array from some object
set comps = JavaWindow("SwingSet").JavaInternalFrame("Internal Frame Generator").Object.getComponents()
'This is the actual workaround - notice the special undocumented command mic_arr_get
set currComp = comps.mic_arr_get(0)
'Now that we have the item we want from the array, let’s print it
msgbox currComp.toString()
Let’s review. The first code line is just there to put the array into a more accessible name – comps.
The second line is the most important here – it uses an undocumented method – mic_arr_get, to retrieve the first item in the array (since we send index=0 as the parameter).
The third line just prints the item’s content.
According to Tsachi there are two such methods:
mic_arr_get – Receives an index and returns the item at that index in the array. The returned item will always be an object (so we have to use .ToString).
mic_arr_set – Receives an index and an object and sets the appropriate item in the array.
There’re also more sophisticated versions for mic_arr_get: instead of returning an object and then turning it into a sting (or an integer, etc), you can perform both actions in a single action by using these specialized methods:
mic_arr_get_int : will return the data as an integer
mic_arr_get_char : will return the data as a single char
mic_arr_get_double : will return the data as a double (real) number
mic_arr_get_long : will return the data as a long number
mic_arr_get_short : will return the data as a short number
mic_arr_get_byte : will return the data as a byte number
mic_arr_get_boolean : will return the data as a boolean
Similarly, you can use the specialized methods for inserting specific data-types into an array:
mic_arr_set_int
mic_arr_set_char
mic_arr_set_double
mic_arr_set_long
mic_arr_set_short
mic_arr_set_byte
mic_arr_set_boolean
Thanks Tsachi, for contributing to the global QTP community!


Yaron Assa




June 23rd, 2008 at 8:15 pm
I wonder just how many of these undocumented features are out there?
Dave