levi_bryant
12 years agoContributor
Better way to deal with a list of WaitObjects
Sometimes I have a large list of Objects that are required to get to the object that I really need to use. Sometimes one of the objects int the list will not exist. If one of those objects does not exist then I want to handle it rather then get a missing object error. The best way so far of dealing with this is using an if statement for each one. It seems like there should be a better way of dealing with this.
Var MyObject = WPFObject("object1").WPFObject("object2").WPFObject("object3)...
If the first object is missing then all objects in list will be missing and I will get an error.
So I do a check for the first objects.
if(WaitWPFObject("object1").Exists)
Var MyObject = WPFObject("object1").WPFObject("object2").WPFObject("object3)...
If I am lucky then if the first object exists then all objects after it will exist as well.
However, sometimes I am unlucky and the first object will exist but not the second. In that case I can do something like this.
if(WaitWPFObject("object1").Exists)
if(WaitWPFObject("object1").WaitWPFObject("object2").Exists)
Var MyObject = WPFObject("object1").WPFObject("object2").WPFObject("object3)...
I can keep doing this for each object that may not exist. Eventually I have a huge section of if statements.
Is there an easier or better way to do this?
Var MyObject = WPFObject("object1").WPFObject("object2").WPFObject("object3)...
If the first object is missing then all objects in list will be missing and I will get an error.
So I do a check for the first objects.
if(WaitWPFObject("object1").Exists)
Var MyObject = WPFObject("object1").WPFObject("object2").WPFObject("object3)...
If I am lucky then if the first object exists then all objects after it will exist as well.
However, sometimes I am unlucky and the first object will exist but not the second. In that case I can do something like this.
if(WaitWPFObject("object1").Exists)
if(WaitWPFObject("object1").WaitWPFObject("object2").Exists)
Var MyObject = WPFObject("object1").WPFObject("object2").WPFObject("object3)...
I can keep doing this for each object that may not exist. Eventually I have a huge section of if statements.
Is there an easier or better way to do this?
Hi Levi,
The Wait methods require using the timeout parameter. Otherwise, they don't differ from the WPFObject methods.
For example:
if(WaitWPFObject("object1", 5000).Exists)
Var MyObject = WPFObject("object1").WPFObject("object2").WPFObject("object3)...