Discussion:
Confusion about References
Jim Wagner
2017-09-19 18:00:09 UTC
Permalink
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 ***@xojo.com
Jon Ogden
2017-09-19 18:52:27 UTC
Permalink
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
Post by Jim Wagner
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 ***@xojo.com
Jim Wagner
2017-09-19 19:57:06 UTC
Permalink
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/>
Post by Jon Ogden
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.
Dim c as New MyClass
Dim d as MyClass = c
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.
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
Post by Jim Wagner
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 ***@xojo.com
Markus Winter
2017-09-19 20:43:51 UTC
Permalink
Post by Jim Wagner
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.
Again, not a good idea. You are just moving your external methods to another place.

Rather have the methods IN the class as Jon suggested and call it there. Good OOP means things should be self-contained, so any operation on a class should be done by a method in the class (like Clear, Init, etc).

MfG

Markus




To unsubscribe, email ***@xojo.com
Jon Ogden
2017-09-19 20:45:18 UTC
Permalink
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
Post by Jim Wagner
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/>
Post by Jon Ogden
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.
Dim c as New MyClass
Dim d as MyClass = c
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.
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
Post by Jim Wagner
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 ***@xojo.com
Jim Wagner
2017-09-19 20:47:33 UTC
Permalink
Thanks Jon and Markus for the suggestions.

Jim


James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Jon Ogden
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
Post by Jim Wagner
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/>
Post by Jon Ogden
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.
Dim c as New MyClass
Dim d as MyClass = c
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.
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
Post by Jim Wagner
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 ***@xojo.com
Jim Wagner
2017-09-19 21:50:15 UTC
Permalink
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/>
Post by Jon Ogden
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
Post by Jim Wagner
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/>
Post by Jon Ogden
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.
Dim c as New MyClass
Dim d as MyClass = c
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.
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
Post by Jim Wagner
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 ***@xojo.com
Jon Ogden
2017-09-19 21:55:29 UTC
Permalink
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
Post by Jim Wagner
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
Post by Jon Ogden
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
Post by Jim Wagner
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
Post by Jon Ogden
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.
Dim c as New MyClass
Dim d as MyClass = c
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.
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
Post by Jim Wagner
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
To unsubscribe, email us here.
To unsubscribe, email us here.
To unsubscribe, email us here.
To unsubscribe, email us here.
To unsubscribe, email us here.
To unsubscribe, email ***@xojo.com
Jim Wagner
2017-09-19 22:09:08 UTC
Permalink
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/>
Post by Jon Ogden
For i as Integer = 0 to NumClassesToReset
ClearClass(MyClasses(i))
Next
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
Post by Jim Wagner
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/>
Post by Jon Ogden
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
Post by Jim Wagner
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/>
Post by Jon Ogden
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.
Dim c as New MyClass
Dim d as MyClass = c
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.
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
Post by Jim Wagner
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 ***@xojo.com
Markus Winter
2017-09-19 22:20:45 UTC
Permalink
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?
That's what class functions aka shared functions are for: one function shared by all instances of a class.

I strongly recommend you read up on OOP in Xojo. There are some articles on the xDev store.

MfG

Markus

Sent from my iPad


To unsubscribe, email ***@xojo.com
Jim Wagner
2017-09-19 22:27:26 UTC
Permalink
Thanks, Markus -

Yes, I do need to do some reading.

Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Markus Winter
Post by Jim Wagner
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?
That's what class functions aka shared functions are for: one function shared by all instances of a class.
I strongly recommend you read up on OOP in Xojo. There are some articles on the xDev store.
MfG
Markus
Sent from my iPad
To unsubscribe, email ***@xojo.com
Markus Winter
2017-09-19 22:27:31 UTC
Permalink
Post by Markus Winter
I strongly recommend you read up on OOP in Xojo. There are some articles on the xDev store.
I like the one by Scott Steinman http://www.xdevmag.com/browse/6.5/6507/


To unsubscribe, email ***@xojo.com
Markus Winter
2017-09-19 22:35:12 UTC
Permalink
Sorry, old link.

Try http://www.xdevlibrary.com/

MfG

Markus

Sent from my iPad




To unsubscribe, email ***@xojo.com
Jim Wagner
2017-09-19 22:47:10 UTC
Permalink
Got the new link in your previous post. Sorry for not acknowledging that.

Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Markus Winter
Sorry, old link.
Try http://www.xdevlibrary.com/ <http://www.xdevlibrary.com/>
MfG
Markus
Sent from my iPad
To unsubscribe, email ***@xojo.com
Jim Wagner
2017-09-19 22:39:37 UTC
Permalink
Wow, thats a blast from the past!

I had either totally forgotten about or maybe never knew about xdevmag.com <http://xdevmag.com/>

But, I DO remember Scott.

Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Markus Winter
I strongly recommend you read up on OOP in Xojo. There are some articles on the xDev store.
I like the one by Scott Steinman http://www.xdevmag.com/browse/6.5/6507/ <http://www.xdevmag.com/browse/6.5/6507/>
To unsubscribe, email ***@xojo.com
Jon Ogden
2017-09-20 03:13:42 UTC
Permalink
This post might be inappropriate. Click to display it.
Jim Wagner
2017-09-20 04:17:38 UTC
Permalink
Hello, Jon -

That seems like a pretty reasonable analysis. I’m OK with that. Thanks.

Cheers,
Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Jon Ogden
Jim,
I’m pretty sure the class instances all use the same code space of the super to execute. Think of it this way

Every single control that Xojo has in the language is really a Class. They all have their own functions and methods and properties, etc. Think how inefficient it would be if they all had their own copies of the code and it was literally duplicated across hundreds or thousands of controls in an app. Sounds pretty inefficient. So I am pretty sure that each instance of a class calling a method or function of the class wastes no more memory than some line of code calling a function or method stored in a module.
Jon
Post by Jim Wagner
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/>
Post by Jon Ogden
For i as Integer = 0 to NumClassesToReset
ClearClass(MyClasses(i))
Next
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
Post by Jim Wagner
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/>
Post by Jon Ogden
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
Post by Jim Wagner
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/>
Post by Jon Ogden
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.
Dim c as New MyClass
Dim d as MyClass = c
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.
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
Post by Jim Wagner
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 ***@xojo.com
Markus Winter
2017-09-20 05:25:04 UTC
Permalink
I’m pretty sure the class instances all use the same code space of the super to execute.
Each instance has a function pointer that points to the memory address where the code is.

Each instance has its own space for properties.

MfG

Markus

Sent from my iPad


To unsubscribe, email ***@xojo.com

Continue reading on narkive:
Loading...