05-02-2007 09:55 AM
05-02-2007 10:03 AM
I have done this already. I used the .net MSXML XMLdoc class to both create and parse XML docs it is not too hard but make sure you always keep a reference to the .net object because once it goes out of scope you loose it and it becomes invalid. To tell if an object has been constructed, you might be able to keep a boolean flag in a shift register. Are you wrapping each function or are you trying to use an action engine? The problem with the action engine (functional globals) is the scope of the object. Other approaches it to see if the object refnum is valid with a method call and trap the error (not sure if you can trap the .net errors silently).
Paul
05-03-2007 04:14 AM
My intension is to create a LabVIEW class which handles the needed refnums itself. The XmlDocument refnum will be a private member of my class. So I don't need an action engine (is it the same like a global variable in the LabVIEW2.0 style?) or boolean flags. To check if its a valid refnum I could use the comparision "Not a number/path/refnum?". So each of my member VIs has to do this check first before it operates on the refnum. Each instance of the class has it's own refnum and I don't have to take care about the scope.
05-07-2007 07:27 AM
If the programmer does not use the init function you will not have a valid refnum. This is a programming error which will only be caught at runtime. One method for forced initialization is to use the first call and have the class initialize the XMLdom with a constructor call. Are you using the 8.2 class structure? I haven't played too much with this so I am not sure how the first call works in this. From a pure OO standpoint you can add an isInitialized class private member. By default this is false and is toggled true on the init method. As for garbage collection, the .net references seem to stay active if a caller of the .net node is referenced, they are collected when their instance is nolonger in LV's mamory (ie pass a wire with the reference throughout the code where the .net is needed). Good luck, I like the msxml .net library and have found it increasingly used in my code.
Paul
05-07-2007 10:20 AM
05-07-2007 10:59 AM
I have not found too much on memory management using .net, but from my experience you can force a manual close of a .net object just as done with active X but I have also found that if a .net object in not referenced and you try to call that instance again you will get an error so I concluded that the garbage collector deallocated this object. In c# the .net runtime engine is susposed to keep a count of the references to the object, when the grabage collector runs and sees this count =0 then the object is deallocated. I would guess that if the object is not referenced by any labview vi then the object is marked for outomatic collection as well. I could be wrong though. You can also call an objects destructor and invoke the GC but usually ythis is not necessary.
Paul