Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Jun 29, 2017 3:53 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: programmmically accessing objects through control
PostPosted: Thu May 30, 2013 5:16 pm 
Offline

Joined: Wed Sep 15, 2010 1:48 pm
Posts: 84
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?

_________________
RS2012r2 Pro Win


Top
 Profile  
Reply with quote  
 Post subject: Re: programmmically accessing objects through control
PostPosted: Thu May 30, 2013 6:17 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You have to cast the control as the proper type.

Listbox(control(x)).HasHeading


Top
 Profile  
Reply with quote  
 Post subject: Re: programmmically accessing objects through control
PostPosted: Fri May 31, 2013 12:24 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
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

_________________
Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group