Re: Confusion about References

Jim Wagner <[email protected]> Tue, 19 Sep 2017 15:09:08 -0700
Newsgroups gmane.comp.lang.realbasic.user
Message-ID <[email protected]>
Thanks, Again -

I guess I am still stuck in the highly memory constrained really small microcontroller mindset where the idea of creating so many duplicates of a single function. Unless, of course, under the hood, those class instances really do not create their own copies of function but access the super’s definition for the actual execution. Or, do I just throw up my hands and say “memory be hanged” and blast ahead, chewing up the RAM bytes?

Appreciate your thoughts,

Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>




> On Sep 19, 2017, at 2:55 PM, Jon Ogden <[email protected]> wrote:
> 
> Nope. In fact all the better. Look you have to call your clear or reset in a loop anyhow. So you can do it your way:
> 
> For i as Integer = 0 to NumClassesToReset
>    ClearClass(MyClasses(i))
> Next
> 
> Or our way:
> 
> For i as Integer = 0 to NumClassesToReset
>    MyClasses(i).ClearClass
> Next
> 
> I guarantee you that as you go along you’ll find other functions that can go inside the classes as well as class interfaces and events, etc. 
> 
> If they are simply a container of items like you say then just use a dictionary to hold them. 
> 
> Jon
> 
> Sent from my iPhone
> 
> On Sep 19, 2017, at 4:50 PM, Jim Wagner <[email protected] <mailto:[email protected]>> wrote:
> 
>> Does this change if there are hundreds or even thousands of instances of the MyClass? I really picture their function more like a struct to hold certain data,  all being a properties of a master class that organizes them and operates on them.
>> 
>> Thanks
>> Jim
>> 
>> James Wagner
>> Oregon Research Electronics
>> http://www.orelectronics.net <http://www.orelectronics.net/>
>> 
>> 
>> 
>> 
>>> On Sep 19, 2017, at 1:45 PM, Jon Ogden <[email protected] <mailto:[email protected]>> wrote:
>>> 
>>> 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] <mailto:[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 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]