Wrote these functions for you to test. I'm curious if it is any quicker for you.
I tested on a form with about 8000+ controls and it returns in approx 6 seconds.
Not great...but better than 2 minutes I guess :robotindifferent:.
[Edit] removed the second split in findobject function (was used in testing)
function Get_Control(PropName, PropVal){
//Creates arrays of property names and values
propArray = PropName.split(",");
valuesArray = PropVal.split(",");
// Searches for the control
var p = Project.Variables.Process;
// Depth at 1000 because we do not know where the control might be.
Project.Variables.Control = findobject(p, propArray, valuesArray, 1000);
// Processes the search results
if (Project.Variables.Control.Exists){
Log.Message(Project.Variables.Control.Name);
}
else{
if(!Project.Variables.Optional){
Log.Message("Failed to Identify an object by the property value specified.", PropName + " " + PropVal)
Log.Error("The object was not found.");
}
else{
Project.Variables.MoveToNextStep = true;
}
}
}
function findobject(parentObject,propArray,valuesArray,depth) {
//propArray = propArray.split(",");
//valuesArray = valuesArray.split(",");
parentObject.Refresh();
/*
check all visibleonscreen first
*/
var VOSArray = parentObject.FindAll(["Visible","VisibleOnScreen"],[true,true],depth,false).toArray();
var tmpObj = matchproperty(VOSArray, propArray, valuesArray,depth);
/*
check all not visibleonscreen
*/
if (!tmpObj.Exists) {
var NOVOSArray = parentObject.FindAll(["Visible","VisibleOnScreen"],[true,false],depth,false).toArray();
var tmpObj = matchproperty(NOVOSArray, propArray, valuesArray,depth);
}
CollectGarbage();
return tmpObj;
}
function matchproperty(objArray, propArray, valuesArray) {
/*
testcomplete wild card replacement
.* same as * , . same as ?
reverse the objArray so a top-down (as per the obj browser) ascending search is performed
*/
objArray = objArray.reverse();
/*
iterate objArray and propArray to determine matching object
*/
for (var o = 0; o < objArray.length; o++ ) {
for (var p = 0,match = true; p < propArray.length;p++) {
if (!aqObject.IsSupported(objArray[o], propArray[p])) {
match = false;
break;
}
var objval = objArray[o][propArray[p]];
var searchresult = RegExp("^" + valuesArray[p] + "$","i").exec(objval);
if (!searchresult || searchresult.index != 0) {
match = false;
break;
}
}
if (match) {return objArray[o];}
}
/*
if no match return stub object
*/
return Utils.CreateStubObject();
}