Forum Discussion

coharness's avatar
coharness
Occasional Contributor
7 years ago
Solved

Object sometimes doesn't support Exists

I have been having an issue throughout some of my scripts where an object suddenly doesn't support the Exists property. When running through the below code, sometimes the script will crash on the if (key.Exists) line. The error is Object doesn't support this property or method. But it's not consistent. Sometimes I get through the script without any problems. When I add a breakpoint and run aqObject.isSupported(key, "Exists"), it returns true. And when I check the object in the Locals tab and the Object Browser it says the Exists property is true.

 

function findKey(propertyName, character, shiftMode) {
  var keyboard = getKeyboard()
  
  var key = keyboard.findChild(propertyName, character, 2)
  
  if (key.Exists) {
    keyboard.set_ShiftMode(shiftMode)
    key.Click()
    
    return true
  }
  
  return false
}

According to the documentation for findChild, "If no object matching the search criteria was found, the FindChild method returns a stub object that only contains the Exists property equal to False." So why does my object sometimes not have the property?