Well, there are no such things as "global objects", in that there aren't
any "local objects". Objects are just objects, and you can instantiate
them. Every time you assign a new variable to them or pass them somewhere
a reference count goes up, and they cease to exist when all references are
gone. If you look at an object variable, it'll be something like <.... 3
....>. That number in the middle is the reference count. If you assign an
object to a global variable, the variable won't pass out of scope, so the
object stays instantiated, until you set the variable to something else.
As far as what you're doing, what strikes me is that you are setting
myXMLData to an instance of the parser, which is fine, then you do some
things, then you pass the instance down to foobarxmlhandler.
All that's fine, but the first thing foobarxmlhandler does is make ANOTHER
instance of the parser, stored in myXMLData, then you immediately discard
that instance by setting myXMLdata to the parameter (which you just passed
in), and that parameter is already an instance of the parser.
So, I don't know what you're trying to accomplish here, but I'd say:
1) Don't forget to close off your instance of the Xtra when you're
done. This means the end of the XMLreceive function should have a
statement like myXMLData =0. This isn't technically necessary since the
variable goes out of scope anyway, but it's good practice.
2) Since you pass the variable down to foobarxmlhandler, foobarxmlhandler
now has an already-instantiated version of the Xtra. You can start using
it right away, as in:
on foobarxmlhandler(foobarXMLdata)
if (foobarXMLData.doneParsing()) then
-- whatever
end if
end
If you just want it to be called myXMLdata then just make the parameter
name be myXMLdata.
- Tab
At 06:53 PM 2/6/02 -0500, Matthew DeSimone wrote:
>Quick question about how objects work. I'm using a global XML parser
>object to go through data and call handlers
>where appropriate. These handlers then access the global object.
>
>However, issues arise in the fact that I am constantly receiving this
>xml data. If I am not done in handlerX with xmlDataY when a new
>document comes in, the data in the object will be overwritten in the
>middle of my interaction with it.
>
>To solve this, I thought maybe I could do something like the following,
>eliminating the global xml object. Basically, I want to know if this
>code is legal, as I seem to be getting some random errors.
>
>on XMLrecieve
>
> myXMLdata = new(xtra "xmlparser")
>
> --do xml parsing and examination
> if (myXMLdata.child[1].name = "foobar") then
> --pass the object as a param here
> foobarxmlhandler(myXMLdata)
> end if
>
>end XMLreceive
>
>
>on foobarxmlhandler(foobarXMLdata)
>
> myXMLdata = new(xtra "xmlparser")
> myXMLdata = foobarXMLdata
>
> do stuff
>
>end foobarxmlhandler
>
>
>
>~matt desimone
>[EMAIL PROTECTED]
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]