Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Apr 08, 2020 2:33 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Property call
PostPosted: Fri May 17, 2013 3:43 am 
Offline

Joined: Tue Oct 30, 2012 4:23 am
Posts: 22
Hello,

I have a idea, but I don know if it could work.

I need to pass PROPERTY to Function or Sub.

Sub MySub (Value as string, Prop as DontKnow)
MyVar.Prop=Value
End Sub


Is possible something like this ?

Thanks

Martin

_________________
---

@MacOS 10.7.5/MBPro


Top
 Profile  
Reply with quote  
 Post subject: Re: Property call
PostPosted: Fri May 17, 2013 5:40 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Quote:
I need to pass PROPERTY to Function or Sub.


Why?

I have to assume that your example code is just an example.
because
MyControl.Property=Value
does the job perfectly well

You dont need to do
MySub(Value,MyControl.value)

If the Mysub could put any old value into the property, then you only need a function:

MyControl.Property=MySub(Value)


Where (probably) MySub() returns a variant. Sloppy, but possible.


Top
 Profile  
Reply with quote  
 Post subject: Re: Property call
PostPosted: Fri May 17, 2013 6:17 am 
Offline

Joined: Tue Oct 30, 2012 4:23 am
Posts: 22
Hello,

It is not control, but variable and property is defined by me. (variable is created via class)
I have MyClass with property1-property5
I have Variable
Dim MyVar as MyClass


And now I have Sub where I want to process MyVar.propertyX
Code is equal for each property, but I want to select which property will be processed.

Now I have:
MySub (PropertyType as integer)
Select case PropertyType
case 1
Code for MyVar.Property1
case 2
Code for MyVar.Property2
.
.
.
End Sub



And I need

MySub (Something like Property)
Code for MyVar.ReceivedProperty
End Sub


Generally I want to use 1 code instead of X codes for each property

Thanks Martin

_________________
---

@MacOS 10.7.5/MBPro


Top
 Profile  
Reply with quote  
 Post subject: Re: Property call
PostPosted: Sat May 18, 2013 6:02 am 
Offline

Joined: Thu Apr 10, 2008 6:03 am
Posts: 303
Location: Paris-La Défense, France
It seems that what you are looking for is the Variant type.

This might help:

Function MySub(theVar As Variant) As String
Select Case theVar.Type
Case Variant.TypeDate
Return "Date"
Case Variant.TypeDouble, Variant.TypeCurrency, Variant.TypeInteger, Variant.TypeLong, Variant.TypeSingle
Return "Double"
Case Variant.TypeArray
Return "Array"
Case Variant.TypeBoolean
Return "boolean"
Case Variant.TypeCFStringRef
Return "CFStringRef"
Case Variant.TypeColor
Return ""
Case Variant.TypeCString
Return ""
Case Variant.TypeCurrency
Return ""
Case Variant.TypeDate
Return ""
Case Variant.TypeDouble
Return ""
Case Variant.TypeInteger
Return ""
Case Variant.TypeLong
Return ""
Case Variant.TypeNil
Return ""
Case Variant.TypeObject
Return ""
Case Variant.TypeOSType
Return ""
Case Variant.TypePString
Return ""
Case Variant.TypePtr
Return ""
Case Variant.TypeSingle
Return ""
Case Variant.TypeString

If theVar.StringValue.len = 19 then
Dim D As new Date
try
D.SQLDateTime = theVar
Return "Date"
Catch UnsupportedFormatException
Return ""
end try
else
Return ""
End If
Case Variant.TypeStructure
Return ""
Case Variant.TypeWindowPtr
Return ""
Case Variant.TypeWString
Return ""
else
Return ""
End Select
End Function

_________________
Check my Website for high quality custom controls and classes (no plugins) for Windows, Mac OS and Linux
REALBasic 2012 R2 on Win 7 & Mac OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: Property call
PostPosted: Sun May 19, 2013 5:42 am 
Offline
User avatar

Joined: Fri May 16, 2008 8:00 am
Posts: 37
Location: Germany
Read about Operator_Convert methods in the documentation.

Carsten


Top
 Profile  
Reply with quote  
 Post subject: Re: Property call
PostPosted: Mon May 20, 2013 3:32 am 
Offline

Joined: Tue Oct 30, 2012 4:23 am
Posts: 22
Hello,

I just solve it with Introspection,

Sub MySub (PropertyToChange as String, ValueToChange as Integer)
Dim myProperties() as Introspection.PropertyInfo = Introspection.GetType(MyVar).GetProperties

For ccc as Integer=0 to Ubound(myProperties)
if instr(myProperties(ccc).name,PropertyToChange)>0 then
myProperties(ccc).Value(MyVar)=ValueToChange
exit
end if
Next
End Sub


Thanks

_________________
---

@MacOS 10.7.5/MBPro


Top
 Profile  
Reply with quote  
 Post subject: Re: Property call
PostPosted: Tue May 21, 2013 4:37 am 
Offline

Joined: Thu Apr 10, 2008 6:03 am
Posts: 303
Location: Paris-La Défense, France
Just my two cents you should use this code if it is possible.

Sub MySub (PropertyToChange as String, ValueToChange as Integer)
Dim myProperties() as Introspection.PropertyInfo = Introspection.GetType(MyVar).GetProperties

For ccc as Integer=0 to Ubound(myProperties)
if myProperties(ccc).name = PropertyToChange then //Check that the name is exactly equal to PropertyToChange
myProperties(ccc).Value(MyVar)=ValueToChange
exit
end if
Next
End Sub


Using your code, you could end up having two properties with the same text at the beginning but a different ending:
Background As Boolean
BackgroundColor as Color

When changing Background you might end up changing BackgroundColor instead.

_________________
Check my Website for high quality custom controls and classes (no plugins) for Windows, Mac OS and Linux
REALBasic 2012 R2 on Win 7 & Mac OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: Property call
PostPosted: Tue May 21, 2013 5:02 am 
Offline

Joined: Tue Oct 30, 2012 4:23 am
Posts: 22
Yes you are right.... :idea:

But pasted code was only for demonstartion how I can use needed property.

Thanks

_________________
---

@MacOS 10.7.5/MBPro


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group