Re: Confusion about References
Jon Ogden <[email protected]> Tue, 19 Sep 2017 15:45:18 -0500
| Newsgroups | gmane.comp.lang.realbasic.user |
|---|---|
| Message-ID | <[email protected]> |
So are each of these classes sub-classes of the ClassMaster class? I encourage you to put a function in the class that you call that does whatever you want done to the entire class itself such as resetting it. It just makes it cleaner and more portable in my mind. Say you write this class and then you want to use it in another project. Now you have to make sure you copy over all that reset code, etc. from outside the class. If it was all in the class, it all goes with it and can be easily called - less work down the road. Less chance for missing something when copying to the new project. Jon > On Sep 19, 2017, at 2:57 PM, Jim Wagner <[email protected]> wrote: > > Thanks, Jon - > > That clears up a whole bunch of issues. > > Actually, I am going to have a ClassMaster class that holds the various instances of MyClass as properties and THAT ClassMaster will have a bunch of methods to operate on those property classes. This is just the first step toward that end. > > Appreciate your help and explanation. > > Jim > > James Wagner > Oregon Research Electronics > http://www.orelectronics.net <http://www.orelectronics.net/> > > > > >> On Sep 19, 2017, at 11:52 AM, Jon Ogden <[email protected] <mailto:[email protected]>> wrote: >> >> So to answer your question at the end, you can’t pass objects ByRef. That’s because once you create an object, it exists and any other “copies” of that object are really the same object unless a “New” one is create. Let me explain with example. >> >> Let’s say you have your class called MyClass. Let’s say I do this: >> >> Dim c as New MyClass >> >> Dim d as MyClass = c >> >> Any operations now on d will also apply to c. They are the SAME object - just different references to the same object. So if I do: >> >> c.Stop = True >> d.Stop = False >> >> And then I go and look at the value of C.Stop in the debugger, I will see it as false. >> >> The only way to make it different is to do this: >> >> Dim c as New MyClass >> Dim d as New MyClass >> d.stop = c.stop >> etc.. >> >> As soon as you set one object equal to another, they become different references to the same object. >> >> So if you want to have a method to operate on the object, you use >> >> ClassClear(TheClass as MyClass) >> >> Objects are not copied like properties when passed as parameters. They are “ByRef” by default. >> >> Now, why have an external method that you call to clear the class? Why not have a method in the class itself? Say MyClass.Clear. Then just call the clear method on the instance of the class that you want to clean up? That to me seems better than an external method that is doing the same thing. >> >> Jon >> >> >>> On Sep 19, 2017, at 1:00 PM, Jim Wagner <[email protected] <mailto:[email protected]>> wrote: >>> >>> Greetings, NUG - >>> >>> Its been a while since I have tried to do something like this, and I’m tangled up with the right procedure to use. >>> >>> I have a class, lets call it MyClass and it has a bunch of properties, stop as boolean, sequencenum as integer, and so forth. >>> >>> I have a number of instances of this class (properties of various windows), lets call them Window1.MyClassA, Window2.MyClassB, and so forth. >>> >>> I have a function to “reset” the properties of these classes, after the class has been used. I would like to pass a reference to the one being reset and operate on its properties, with the result that the ORIGINAL class is reset. >>> >>> I have tried: ClassClear(byref TheClass as MyClass) >>> >>> But, when I try to call it using ClassClear(Window1.MyClassA) >>> >>> I get an error that reads: "You can’t pass an expression as a parameter that is defined as ByRef" >>> >>> Can someone suggest a “proper” way to do this? >>> >>> Many thanks >>> Jim >>> >>> James Wagner >>> Oregon Research Electronics >>> http://www.orelectronics.net <http://www.orelectronics.net/> >>> >>> >>> >>> >>> >>> To unsubscribe, email us here. <mailto:[email protected]> >> >> To unsubscribe, email us here. <mailto:[email protected]> > > To unsubscribe, email us here. <mailto:[email protected]> To unsubscribe, email [email protected]