New topic: [Solved]How to create class variables?
<http://forums.realsoftware.com/viewtopic.php?t=45514> Page 1 of 1 [ 7 posts ] Previous topic | Next topic Author Message Carharttguy Post subject: [Solved]How to create class variables?Posted: Wed Oct 03, 2012 2:08 pm Joined: Wed Sep 17, 2008 2:45 pm Posts: 193 Hello How can I use class variables in RS? Class variables are variables that are instance independent, also called 'Shared' or 'Static' members in other languages. Thanks! _________________ My native language is not English. Last edited by Carharttguy on Thu Oct 04, 2012 2:01 am, edited 1 time in total. Top timhare Post subject: Re: How to create class variables?Posted: Wed Oct 03, 2012 2:41 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 11706 Location: Portland, OR USA You can use them like any other property of the class. Eg., someInstance = New MyClass someInstance.SharedVariable = somevalue You can also use them directly, without an instance. MyClass.SharedVariable = somevalue Keep in mind, though, that even though in the first usage, it looks just like a normal property, the value is shared between all instances (because it belongs to none of them). Top Carharttguy Post subject: Re: How to create class variables?Posted: Wed Oct 03, 2012 2:49 pm Joined: Wed Sep 17, 2008 2:45 pm Posts: 193 My questioni was kind of wrong, I meant to ask, how to create class variables! Sorry for that mistake. Edit: Nevermind, you already told it, they're just normal properties, but used as class variables. So I cannot create a class variable, that is only accessible directly on the classname, but not on the instances? Thanks for your time. _________________ My native language is not English. Top timhare Post subject: Re: How to create class variables?Posted: Wed Oct 03, 2012 2:57 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 11706 Location: Portland, OR USA You create them through the Project -> Add -> Shared Property menu. Top markwalsh Post subject: Re: How to create class variables?Posted: Wed Oct 03, 2012 3:20 pm Joined: Wed May 20, 2009 4:43 pm Posts: 889 Carharttguy wrote:So I cannot create a class variable, that is only accessible directly on the classname, but not on the instances? If I understand what you are asking, any shared property or method will be available to all instances of the class, as well as the class itself. As Tim pointed out, the property will share a single value whether accessed from the class or it's instances. _________________ RB 2009r4 Windows XP Top timhare Post subject: Re: How to create class variables?Posted: Wed Oct 03, 2012 3:55 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 11706 Location: Portland, OR USA You misunderstand. Quote:Nevermind, you already told it, they're just normal properties, but used as class variables. They are not normal properties. They are true shared properties. Quote:So I cannot create a class variable, that is only accessible directly on the classname, but not on the instances? Don't get tripped up by the fact that you can use the instance to access them. That is syntactic sugar just to make things clearer/easier, depending on your preferred method of use. You are still accessing the single class property value. Some people just like to use the instance name so their code looks more uniform. If you want to only use the class name, to differentiate the usage, then go right ahead. The result is the same either way. Top Carharttguy Post subject: Re: How to create class variables?Posted: Thu Oct 04, 2012 1:59 am Joined: Wed Sep 17, 2008 2:45 pm Posts: 193 timhare wrote:You misunderstand. Quote:Nevermind, you already told it, they're just normal properties, but used as class variables. They are not normal properties. They are true shared properties. Quote:So I cannot create a class variable, that is only accessible directly on the classname, but not on the instances? Don't get tripped up by the fact that you can use the instance to access them. That is syntactic sugar just to make things clearer/easier, depending on your preferred method of use. You are still accessing the single class property value. Some people just like to use the instance name so their code looks more uniform. If you want to only use the class name, to differentiate the usage, then go right ahead. The result is the same either way. Ok! Thanks for pointing that out! Using an instance for accessing a class variable looks confusing to me. But as you say, syntactic sugar! Thanks again for your answer, helped me a lot. _________________ My native language is not English. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 7 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
