Or use Introspection.. This code is from the macoslib project, but works on Cocoa, Windows and Linux builds.. Use the HasProperty function to determine if the object (control) has the property and if it does, use the PropertyValue function to the get the property's value.. Please note that this will work even if you do not cast the control to the proper type..
Function HasProperty(extends obj as Object, wantedProperty as string) As boolean
//# Returns true if the object has the given property name
Dim myProperties() as Introspection.PropertyInfo= _
Introspection.GetType( obj ).GetProperties
For i as Integer = 0 to Ubound(myProperties)
if myProperties( i ).Name = wantedProperty then
return true //found
end if
Next
return false //Not found
End Function
Function PropertyValue(extends obj as Object, propName as string) As variant
//# Get the property value of the passed object and name
Dim myProperties() as Introspection.PropertyInfo= _
Introspection.GetType( obj ).GetProperties
For i as Integer = 0 to Ubound(myProperties)
if myProperties( i ).Name = propName then
return myProperties( i ).Value( obj )
end if
Next
return nil
End Function