09-13-2005 09:09 AM
Blog for (mostly LabVIEW) programmers: Tips And Tricks
09-13-2005 09:52 AM
09-13-2005 10:07 AM
Well, I know that's not quite true, as you can pass them via connector or global variable, and have one VI work on another VI's controls.
My question is, if the VI is closed, then opened up AGAIN, are the refnums the same? I understand they will not be valid while the thing is closed.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
09-13-2005 10:22 AM
09-13-2005 11:16 AM
--- Right. Since the code that uses them is in the same scope, all is well.
What you can't do, however, is expect to be able to drop a reference constant on a block diagram which refers to a control in a different VI and have it work after closing and opening again (if it's even possible in the first place).
--- Well, sure. If you copy a reference constant from diagram 1, and paste it into diagram 2, you get a new control on front panel 2, as well. That's nothing to do with my question.
A reference from an object outside the current VI will NOT be valid upon re-loading
Well, that's the heart of my question. Since the refnum was obtained whil the VI's FP was open, it's valid at least until the FP is closed. Obviously it can't be used while the FP is closed. When the FP is opened again, there is a refnum to this same control. Is it the same refnum as before?
Your answer is "no". I ran a test (which perhaps I should have done earlier) which says "yes". If I close the main VI, the numbers are different the next time I run it, but as long as the main VI is open, the refnums for the subVI's controls remain the same, no matter how many times I open and close it. This is true on LV 7.0 (win2k) and 7.1 (OS X).
Whether it's guaranteed behavior, or just happenstance, is debatable, but in fact it does work. I'm debating whether I can rely on it.
If you see holes in my thinking, let's hear them.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
09-14-2005 01:46 AM
09-14-2005 05:54 AM
I still maintain that if the VI is really closed (i.e. unloaded from memory, not just a closed front panel) then upon reloading (even if the calling VI remains loaded in the mean time) the references will have changed.
Well, yes, but like you say, that's only possible when calling the thing indirectly, via the VI Server. That's not my case, as I hinted at (but didn't directly say) by the "Open Front Panel when Called" statement. That only works with direct calls, not VI SERVER calls.
If you unload and re-load a VI it's references will change.
--- True, but not pertinent to my situation.
If a VI is loaded within a calling chain and the front panel is closed, the VI is NOT unloaded and thus the references don't change (can you verify this? - list of VIs in memory).
--- This is the heart of it - I knew the VI would not be unloaded (things like uninitalized shift regs and local variables would lose their values if it was). But I didn't know if references would be unchanged or not. If references were simply memory pointers or handles, then they could be changed, simply by using memory in between the first opening and the second. If the controls were truly objects (in the C++ sense), then they could be destroyed upon closing, and re-created upon opening. In that case they might change. If the control ref was some sort of code that described "the third component of the fourth cluster on the panel", then it wouldn't ever change.
In your example (closing and opening a front panel) the references should remain constant as the VI isn't being unloaded from memory.
--- This is indeed what I see.
Now that I think about it, this is the way it has to work. The "local variable" thought above provides a clue. The UI element (HWND on Windows) is probably destroyed on closing and re-created on re-opening. But a control is known to retain its data value if the front panel is closed, and re-opened. This means that the control is more than just the UI element, it's a LabVIEW element. The control reference is a pointer/handle to the LabVIEW element, which exists as long as the FP is loaded. Part of the LabVIEW element is a connection to the UI element, but that's immaterial.
Check if closing the front panel really unloads the VI.
--- This is already known: it unloads the VI ONLY if there are no references to it from VIs still in memory. This is why the SAVE CHANGES? stuff works the way it does - when you close the FP of a changed subVI, you get a message about saving the changes. If you choose not to, the front panel is CLOSED, but the changes are still in memory. If you close the last calling parent, you get ANOTHER warning about the subVI, because this time it's about to be UNLOADed. Last chance.
Thanks for your discussion.
Blog for (mostly LabVIEW) programmers: Tips And Tricks