Forum Discussion

xylian's avatar
xylian
Occasional Contributor
14 years ago

Iterating over ComboBox items

I got a custom ComboBox based on TComboBox. I have to work on very basic methods and params.



I need to itterate over Items List somehow. I tried several methods.



itemCount := aqString.GetListLength(pomObj.Items);  - this method won't help me, it doesnt work with such parametr



-------------------




  itemCount := 0;                        

  while aqConvert.VarToStr(pomObj.Items(itemCount)) <> nil do    

    begin

      itemCount := itemCount + 1;

      Log.Message(itemCount);    

      Log.Message(aqConvert.VarToStr(pomObj.Items(itemCount)));

    end;


here I get infinite loop, even I got just 4 items in comboBox. When I log them I get the blank space.



I tried diferent methods of building a condition such as:

 while pomObj.Items(itemCount) <> nil do

 while pomObj.Items[itemCount] <> nil do 



All loops are infinite

What could I do to iterate over those items?



Regards  

2 Replies

  • Hi Jacek,



    Do I understand it right that the standard wItemCount, wItemList, wItem and other properties do not work for your customized combo box?



    In this case, the best solution is for the developers to build the tested application with debug information (either internal or external). This way TestComplete will have access to all native properties and methods of the combo box and its internal objects. Specifically, if your combo box supports the same API as TComboBox, you should be able to get its items using the Items.Count, Items.Strings(index) and Items.Text properties. I've attached a screenshot with standard TComboBox for your reference.





    here I get infinite loop, even I got just 4 items in comboBox. When I log them I get the blank space.



    I tried diferent methods of building a condition such as:

    while pomObj.Items(itemCount) <> nil do

    while pomObj.Items[itemCount] <> nil do

    All loops are infinite


    Although Items[itemCount] is valid syntax in Delphi, where you can omit default object property names, it's not supported in TestComplete. In TestComplete, the Items property returns an object and you need to directly specify the property name of the object you wish to access - e.g. Items.Strings[itemCount].

    You are getting empty results in the log because the Items object cannot be directly converted to a string, and you are getting an infinite loop because this object isn't nil.



    Hope this answers your questions!