Forum Discussion

jeremy_berge's avatar
jeremy_berge
New Member
15 years ago

TestComplete : dealing with TListview on steroids

Hi, 



For one of our projects (Delphi), we are using a TListView component to display a *big* list of objects (approx 50k).

Each object has some various fields and a unique name (the 6th column of the ListView) 

We'd like TestComplete to be able to select a specific object in this list using it's name,

but as of now, we've been unable to find a solution that is fast enough to be really usable. 

Currently we are using a suboptimal loop (DelphiScript) : 






            for i := 0 to formSel.ListView.wItemCount-1 do begin


              // Obtains Object Name


              s := formSel.ListView.wItem[formSel.ListView.ItemIndex,5];


              if (aqString.Contains(s, TargetName, 0, False) >= 0) then begin


                formSel.ListView.ClickItem(i);


                bSuccess := True;


                break;


              end else begin 


                formSel.ListView.Keys('[Down]');


                s := '';


              end;
end;
(which takes ages to reach the bottom of the list)
According to the documentation, the Obvious ListView.SelectItem() seems to be searching only on the first column (column 0) which does not suit our need; ListView.ClickItem() seems to follow the same pattern.
Did we miss an obvious point ? or did someone find a clever way to workaround this kind of issue ? Is this kind of scenario supported ? Is there a simple way we can make this happen within reasonable delay ?
Thanks for your help and advice !




1 Reply

  • Hi Jay,



    Currently there's no built-in search method for list view controls in TestComplete, so your solution is the way to go. However, depending on your application under test, there may be a way faster than the plain linear search. For example:



    * If the list view is working in virtual mode and data is actually stored in an external data source, say TDataSet, instead of searching for the data source, you could use its native methods (e.g. TDataSet.Lookup) and then map the found record to the list view item. (It is based on the assumption that the data source search is faster than the linear search through the list).



    * If the list view is sorted by the column you're searching in, you can try a faster search algorithm, e.g. the binary search.





    As for your current script, you may be able to speed it up by saving a reference to the list view control in a variable and referring to it via this variable. Also, TestComplete automatically scrolls list controls before selecting an item, so Keys('[Down]') isn't really needed (unless it's there on purpose). Here's the way I'd rewrite it:



    lv := formSel.ListView;



    for i := 0 to lv.wItemCount - 1 do begin

      if (aqString.Find(lv.wItem[i, 5], TargetName, 0, False) >= 0) then begin

        lv.ClickItem(i);

        bSuccess := True;

        break;

      end;

    end;