Re: Confusion about References

Jim Wagner <[email protected]> Tue, 19 Sep 2017 12:57:06 -0700
Newsgroups gmane.comp.lang.realbasic.user
Message-ID <[email protected]>
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]> 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 [email protected]