Object property does not exist right after it passes an exist check?
Given the following piece of code in our script:
Sys.Refresh();
if (aqObject.IsSupported(Sys.Desktop.ActiveWindow(), "MappedName")) { if (Sys.Desktop.ActiveWindow().MappedName != null) //FAILS HERE { <...snip...>
How could it ever be possible that it occasionally fails on the marked //FAILES HERE line with this error:
You are trying to call the "MappedName" method or property of an object that does not exist.
It does a full system refresh, then it checks if MappedName property exist, then if it does so, it goes to the next line and suddenly it doesn't exist anymore?
Well the only place I can think the issue would be is when calling the ActiveWindow() method. You aren't technically checking the same object since you are grabbing a new object with each call to the ActiveWindow() method. That method returns either a Window object or an empty stub object if no top-level window is found. In your code it must return a Window object in the first check then during the second check for whatever reason something changed and TestComplete doesn't think there's any top-level windows so it returns an empty stub object which doesn't have the MappedName property.
I couldn't reproduce the issue myself, but my suggestion is that you return the results for the ActiveWindow() method into a variable, then reference that same variable. So I'd change your code to this:
Sys.Refresh(); activeWindow = Sys.Desktop.ActiveWindow() if (aqObject.IsSupported(activeWindow, "MappedName")) { if (activeWindow.MappedName != '') //FAILS HERE { <...snip...>
Which BTW, the MappedName property is never null. If you don't have a MappedName for an object it returns an empty string which is different than null.