Using Overloaded Functions to Determine Object Types
Vol 7 Issue 6, p.25
Listing 1: nv_pass.of_set( PowerObject )
ll_count = UpperBound( the_str_parm.oc[] ) the_key = lower( trim( the_key ) ) // Trimmed and lowered in of_get() too // Do we have the key already? for i = 1 to ll_count if the_str_parm.oc[ i ].key = the_key then exit // Yes next if i <= ll_count then // The_key exists already the_str_parm.oc[ i ].value = the_powerobject else // The_key does NOT already exist // Insert the key-value pair in the next available array element the_str_parm.oc[ ll_count + 1 ].key = the_key the_str_parm.oc[ ll_count + 1 ].value = the_powerobject end if Listing 2: A typical of_get() variant for string values
// Boolean of_get( str_parm the_str_parm, string the_key, ref string the_string ) if of_get_ac( the_str_parm, the_key ) then return true // Failed to find the_key the_string = iany_value // Set in of_get_ac() return false // Success Listing 3: Check whether the PowerObject is a GraphicObject before the cast string f_context( PowerObject the_object, string the_location ) // Is this is an NVO (or other non-GraphicObject)? if not g.is_graphic_object( the_object ) then // Yes return the_object.ClassName() + '.' + the_location end if // Set up to loop up the GetParent() hierarchy lgo_parent = the_object // Here is the cast! // Loop until we find the enclosing window do while true // Exit on finding a window // Add in the parent's ClassName() ls_context = lgo_parent.ClassName() + "." + ls_context // We're done, if we're at the window level if lgo_parent.TypeOf() = Window! then return ls_context + the_location end if // Get the next parent, i.e. the next layer of the onion, proceeding outward lgo_parent = lgo_parent.GetParent() loop