Wednesday, February 16, 2011

Return an Object by Function as Descriptive programming

Check the below function and code which is defined as an Object by passing property names and property values as an Array, The function returns an Object.

'Set ParentObject = dialog("Login")
'Dim Obj_Name , Obj_Prop
'Obj_Name = Array ("OK","Button")
'Obj_Prop = Array("text","nativeclass")

' Developed Function contains the code to find an object and return to called function
Function Describe_Obj_Arr(ParentObject, Obj_Class, Obj_Name, Obj_Prop)
   bln_Flag = True
    If ParentObject.Exist Then
        Dim des, Chld_Objts, act_val, Chld_Objt_Iter
        Set des = description.Create()
        des("micclass").value = Obj_Class
        If (Obj_Name(0)<>"" and Obj_Prop(0)<>"") Then
            For i= 0 to Ubound(Obj_Name)
                des(Obj_Prop(i)).value = Obj_Name(i)
            Set Chld_Objts = ParentObject.ChildObjects(des)
            If Chld_Objts.count > 0 Then
                act_val = Array()
                For Chld_Objt_Iter=0 to Chld_Objts.count
                    For i= 0 to Ubound(Obj_Name)
                        ReDim preserve act_val(i)
                        act_val(i) = Chld_Objts(Chld_Objt_Iter).getroproperty(Obj_Prop(i))
                    For i = 0 to Ubound(act_val)
                        bln_Flag = True
                        If (Trim(act_val(i)) = Trim(Obj_Name(i))) Then
                            bln_Flag = False
                        End If
                    If bln_Flag = False Then
                        ' Returning an Object to the calling function.
                        Set Describe_Obj_Arr = Chld_Objts(Chld_Objt_Iter)
                        Exit Function ' Exiting function once we found an Object
                    End If
            End If
            Set Describe_Obj_Arr = ParentObject.ChildObjects(des)
            Exit Function
        End If
        Describe_Obj = False
    End If
End Function

'Describe_Obj_Arr(ParentObject, "WinButton", Obj_Name, Obj_Prop).click

"A good threat is worth a thousand tests" - Boris Beizer

No comments:

There was an error in this gadget