Can objects be passed by reference?
Here is why I ask.·
If I create an instance of the vga_text object in the top object and then want to pass a reference to it in a child object, how would I do that? I can’t figure out how to get the runtime address of an object so I can call its methods in a child object.
Here’s a scenario that’s prompting this question.
·I am using the VGA_TEXT object to troubleshoot. I create an instance to it in the top object called “text” and call the methods text.start· and text.str, it works fine there. But when I need to troubleshoot in a lower object and reference it as text.str it won’t compile which I think is because of scoping rules. So if that’s true how do I make this work????
Anthony
If I create an instance of the vga_text object in the top object and then want to pass a reference to it in a child object, how would I do that? I can’t figure out how to get the runtime address of an object so I can call its methods in a child object.
Here’s a scenario that’s prompting this question.
·I am using the VGA_TEXT object to troubleshoot. I create an instance to it in the top object called “text” and call the methods text.start· and text.str, it works fine there. But when I need to troubleshoot in a lower object and reference it as text.str it won’t compile which I think is because of scoping rules. So if that’s true how do I make this work????
Anthony
Comments
You can create a singleton version of the object by redeclaring var data as dat data.
Then you can use the object in any file. Start the object just once in your main object.
As I remember there is another way, but I never adopted it for some reason.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
May the road rise to meet you; may the sun shine on your back.
May you create something useful, even if it's just a hack.
Thanks for the reply but I am not sure I understand what you mean by redeclare var data as dat data. How does that help with object visibility? Can you provide a short example?
Thanks
Anthony
You will not be able to reference dat variables in another object, but the data is shared by any "declaration" of the object.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
May the road rise to meet you; may the sun shine on your back.
May you create something useful, even if it's just a hack.
So·but from what you are telling me I would have to go into the VGA_TEXT object and modify it so that it's a sigleton (move the VARS to DAT). And by doing that I will be able to declare it in the top object·then reference·that· object instance (which I call "text") per my example in the child object with no complie errors. Did I understand you correctly?
Thanks
Anthony
The SPIN language doesn't handle object passing easily. There are ways you can make it happen by jumping through hoops, but it's much easier to just make a singleton version of the class you're interested in using.
Jason
OK now it's getting a little clearer...so·in the case of VGA_TEXT since·it calls VGA...would I also have to modify VGA?
Thanks
Anthony
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
May the road rise to meet you; may the sun shine on your back.
May you create something useful, even if it's just a hack.