Real Software Forums
http://forums.realsoftware.com/

programmmically accessing objects through control
http://forums.realsoftware.com/viewtopic.php?f=10&t=48023
Page 1 of 1

Author:  Dave_ [ Thu May 30, 2013 5:16 pm ]
Post subject:  programmmically accessing objects through control

dim x,i as integer
dim selected,y as string
For i=0 to ListBox1.ListCount
If ListBox1.Selected(i) then
selected = listbox1.list(i)
End if

Next

//list all it could be

for x = 0 to self.ControlCount -1
if selected = Self.Control(x).Name Then
y = Self.Control(x).Name
W_debug.run(y)

if self.control(x) isa listbox then

msgbox "listbox found"

???? self.control(x).Name.HasHeading // properties of self.control(x).name, in this case a listbox



end if


end if
next x


My goal is to read and write object properties programmically, place object properties in a database. If you can iterate through all of the controls using control, how do you access the control properties without spelling out listbox1?

or does every control have to be a control array?

Author:  timhare [ Thu May 30, 2013 6:17 pm ]
Post subject:  Re: programmmically accessing objects through control

You have to cast the control as the proper type.

Listbox(control(x)).HasHeading

Author:  shaosean [ Fri May 31, 2013 12:24 am ]
Post subject:  Re: programmmically accessing objects through control

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

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/