12-29-2012 03:30 AM
Hello,
I would like to programmatically make changes to a (strict) type def. I tried opening a reference to the .ctl but that only seems to work for VI's.
In the specific application I'm trying to make a user should be allowed to edit the items of a ring which is used throughout the whole programm.
Thanks for your time and all the best for 2013,
Bert Hannon
Solved! Go to Solution.
12-29-2012 11:08 AM
First, having a ring as a typedef is not a very good idea. The strings and values of the ring are not part of the data type and are not updated automatically when you edit the typedef. It is true that when you do this for a strict typedef the strings and values are updated, but I believe they're still not always updated for constants of the typedef. I believe you can always force an update if you change the data type (e.g. from I32 to I64 and then back), which is probably easier to do programmatically, but it's still not recommended.
Second, You could try having a typedef enum in the code and translate the enum values to the ring in the UI, but an enum can't be modified while VIs which are using it are in run mode. If you only have to modify UI items (makes sense, since you probably don't add code on the fly), I would suggest simply modifying each instance of the ring in the UI instead of making it a typedef. Modifying typedefs is meant to be an edit-time operation, not a run-time one.
Third, Using the Open VI Reference function to open a reference to the .ctl file should work. Once you do that, I believe you have to use the Front Panel.Controls[] property to get to the actual control.
12-30-2012 11:46 AM - edited 12-30-2012 11:48 AM
I would like to programmatically make changes to a (strict) type def.
--- By definition, you cannot do this. It is the compiler which maintains the connection between an instance of a control, and the TYPEDEF CTL file.
Were you to make this into an executable, there is no compiler available and your code will fail.
a user should be allowed to edit the items of a ring which is used throughout the whole program.
--- One solution is to call a subVI which reports the current list of available items, and attach that list to the STRINGS[ ] property of all rings. Do this when the window containing the ring(s) comes up, and whenever conditions change the list.
--- Another solution which saves memory is to not store the list in the control at all. I have a project with 2800 channel selectors on one panel, each with 200+ channel names. To save memory, I treat it like this:
... The control stores only the currently selected value (i.e., the STRINGS[ ] array has only one entry).
... When a MOUSE DOWN? even occurs, I change the property to be the full list of channels, then let the menu proceed.
... When a VALUE CHANGED event occurs, I set the STRINGS[ ] property back to the single chosen item (removing the large list).
For this case, you don't need to tell the ring what values are avaiable, except right when the user clicks on it.
--- Another solution is to pass reference(s) to the ring(s) to a subVI, which attaches the STRINGS[ ] that are valid at the current time.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
12-31-2012 07:24 AM - edited 12-31-2012 07:28 AM
Ok, I hear it is not possible to let a user make changes to a type def and the reason seems logical to me. I'll stick to my somewhat tampered solution of passing the Strings[] array through the program.
Thanks for your time and a fine new year's eve!
Bert
P.S: @ Steve: interesting way of thinking you put up there, think I'm going to try it out when I got the time