Change your code to this:
var myObject = Aliases.MyApp.MyForm.WaitAliasChild('myObject', 20000);
if (!myObject.Exists){
Log.Error('My object does not exist after 20 seconds');
}
There are ways of adapting this to different ways of executing this but the key is the special method of "WaitAliasChild". There are similar methods (what you may see around the forums as "WaitNNN" methods) that you can read about at https://support.smartbear.com/testcomplete/docs/app-testing/mobile/android/open/checking-object-state/waiting-for-objects.html?q=WaitNNN#using-waitnnn-methods. Each of these operates on the same general principle.
For myself, I create a library function that allows me to, given any parent object, child object name, and designated wait time, I can wait for any given period. Now, I use NameMapping so this assumes aliases and such are designated.
function waitForObject(parentObject, childName, milliseconds = 60000){
var childObject;
if ((parentObject === undefined)||(parentObject === null)) {
throw Error('Parent object is undefined or null');
}
if ((childName === undefined)||(childName === null)) {
throw Error('Child name is missing');
}
childObject = parentObject.WaitAliasChild(childName, milliseconds);
if (!childObject.Exists) {
throw Error('Could not find the object ' + childName + ' in the disgnated ' + milliseconds + 'ms');
}
}
Now, if you're not using mapping or the object you are waiting for is not mapped, then you want to use FindChild (https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findchild-method.html) which, again, you can wrap that in a function like so
function waitForObject(propertiesArray, valuesArray, parentObject, depth, milliseconds = 60000){
var childObject;
var counter = 0;
//I'm leaving out the code to check for proper parameters but I'd recommend bullet proofing your code
childObject = parentObject.FindChild(propertiesArray, valuesArray, depth);
while ((!childObject.Exists) && (counter < milliseconds / 500)) {
aqUtils.Delay(500);
counter++
}
if (counter = milliseconds/500){
return null;
}
return childObject;
}
This function will wait the indicated amount of time. If the object returns within that time, the function returns the object. If not, it returns null.
Again... these are just two ways of doing it... but the key is that you use some built in method (either WaitNNN or FindChild) to look for the object before you check for "exists".