Forum Discussion

electroisok's avatar
electroisok
Occasional Contributor
12 years ago
Solved

Error iterating the items of an object

I use the method FindAllChildren to get a "ContextMenuStrip" object, and I got it correctly. Then I need to iterate inside of the subcontrols of this object. Verifying the object in RAM memory using the Inspect Tool, I can see that the object exists and has the propety "Items" and the size of this array is 2. But when I put the object.Items[0] the test fails. What is the way to index the Items property? 



P.D My code is in Jscript

7 Replies



  • There are couple of mistakes in your code, first of all passing arrays to FindAllChildren is invalid parameter, pass it string values.



    Further object.Items is not an array. you can access Items properties by their names for example object.Items.IsReadOnly or object.Items.Count etc.



    function GetContextMenuStrip()

    {      


      var propertyNames = "FullName";  


      var propertyValues = "*ContextMenuStrip*";


      var objects = Sys.Process("XXXXXXXX").FindAllChildren(propertyNames, propertyValues, 100, true);     //(WHERE XXXXXX is the name of the  process of my application)


      objects = (new VBArray(objects)).toArray();


      var object = objects[0];  //(IT WORKS UP TP THIS LINE)



    ShowMessage (object.Items.Count);


     

    //var array = (new VBArray(object.items())).toArray(); (IN THIS LINE FAILS)


    //  var a = array[0];


    }

     


  • You have to convert it to VBArray, I hope it will work.



    var arrItems = (new VBArray(object.items())).toArray();



    Now you can get array values by writing arrItems[0]

     


  • electroisok's avatar
    electroisok
    Occasional Contributor

    I tried that, but only works to return the objects from the method FindAllChildren, but then   doesn't works to iterate inside the items of these object. I have this code



    function GetContextMenuStrip()


    {      


      var propertyNames = new Array ("FullName");  


      var propertyValues = new Array("*ContextMenuStrip*");


      var objects = Sys.Process("XXXXXXXX").FindAllChildren(propertyNames, propertyValues, 100, true);     (WHERE XXXXXX is the name of the  process of my application)


      objects = (new VBArray(objects)).toArray();


      var object = objects[0]; (IT WORKS UP TP THIS LINE)


      var array = (new VBArray(object.items())).toArray(); (IN THIS LINE FAILS)


      var a = array[0];


    }



    The error is the showed in the image.