04-10-2013 12:12 PM
I have observed several times where some of my control arrays have their elements change order in between debugging sessions.
It's unpredictable when it happens. But the symptoms amount to my controls affecting the wrong secondary control (for instance, LED #2 gets turned on when SWITCH #0 gets pushed).
When I inspect the control arrays, I can find that one or many elements are now out of order. When I fix them again in the UIR, then all is well again.
Any thoughts on how to lock them down in the UIR?
Solved! Go to Solution.
04-11-2013 10:02 AM
ElectroLund,
The only information I've been able to find relating to this problem is an issue that we fixed in CVI 2010 where the order of elements in the control array could change after saving the UIR file. Which version of CVI are you seeing this behavior on?
Beyond that, I'm not sure why we would be seeing this behavior. Is it always the same control that is out of order in the UIR file?
04-11-2013 11:31 AM
I'm using 2012, SP1, and we're on support.
Unfortunately, it's not a repeatable situation and the reordering control arrays aren't always the same ones.
As another data point, I have been using a different IDE to edit my code when this tends to happen. I know that's potentially dangerous, but there are certain features that the CVI editor lacks in my opinion. For instance, is there no way to:
1) display a list of the functions in a C file?
2) highlight other variables/function names if another is double-clicked?
04-12-2013 01:15 PM
Hey ElectroLund,
Hmm. It's unfortunate that we can't repeat the behavior; that would certainly help us figure out why this might be happening. Would it be possible for you to attach the UIR file to your post so we can take a look and see if we can find a way to repeat the behavior?
I believe you are correct that those features are not available in CVI currently. We do have a forum for product ideas, and I think these would be great things to submit there. That forum is located here.
04-15-2013 12:28 PM
I posted those suggestions, Daniel. Could I private message you my UIR?
04-16-2013 08:25 AM
ElectroLund,
Sure, you can send me the UIR via private message, and I'll be happy to take a look at it and see if the same behavior occurs for me. It would also be useful to see a snippet of the code that's accessing the control array, so I can see how you're using it in the application.
04-16-2013 11:38 AM
ElectroLund,
One thing I noticed about your code is that you call the GetCtrlArrayFromResourceID function at the top of each callback. Since the control array shouldn't change while the program runs, I might suggest doing all of these function calls in the main function as soon as the program starts, and just store them for use in the callbacks. That probably isn't contributing to the problem here, but it would make things a bit more efficient.
Nothing is sticking out to me just yet as being a potential cause of the problem. I know you said you've been editing code in an external IDE; to be clear, have you edited the UIR file at all in any external editor?
One thing that was suggested by one of my colleagues was to create the control arrays in source code rather than using the GetCtrlArrayFromResourceID function. This would guarantee that the controls are in the order you wish them to be in, although it would take a bit more code to implement.
04-16-2013 01:35 PM
@Daniel-E wrote:
One thing I noticed about your code is that you call the GetCtrlArrayFromResourceID function at the top of each callback. Since the control array shouldn't change while the program runs, I might suggest doing all of these function calls in the main function as soon as the program starts, and just store them for use in the callbacks.
...to be clear, have you edited the UIR file at all in any external editor?
That's a great idea about my GetCtrlArrayFromResourceID. For some reason, I must have assumed that those were somehow volatile and need to be acquired each time. I will make that change!
No, since the UIR is binary, I don't touch it. I realize that it's very dangerous, particularly if I make changes to the UIR, then I have to keep the external IDE in sync.
Oh well, it hasn't happened in a while, so I'm not too concerned now. Out of curiosity, how would I go about setting the control arrays programmatically? NewCtrlArray? I suppose the advantage to this would be that I wouldn't then need to retrieve the control array handles, correct? Same with control array indices? And could these control arrays simply be created once after the UIR panels are loaded?
04-17-2013 01:33 PM
ElectroLund,
Glad the suggestion to move GetCtrlArrayFromResourceID was helpful!
You'd create a control array by first calling NewCtrlArray, and then use InsertCtrlInArray to add controls to it. As I said, it'd take a bit more work to do this, but it'd be a lot more explicit as far as forcing the controls to be in a certain order. Might be something to look into if this starts happening again in the future.
05-28-2013 03:16 PM
I think I may be closer to understanding when this keeps happening to me. (Sorry, I still haven't taken the time/effort to convert to a programmatic solution of setting my control array ordering)
There seems to be a link to the fact that the elements in a control array are ordered in reverse fashion. For instance, no matter what order I click the controls that I want included in an array, the resulting array is ordered alphabetically in reverse order (see screenshot). This seems odd to me. Why not retain the clicking order? And in my case, I really want the first element I click to be the lowest ordered element in my array (controlarray[0]), because I'm logically referencing these elements in that fashion.
Now on to my reproduction of the bug...
I have found that after I manually reorder the elements in the control array, if I later (like presumably after a UIR save) go into the properties of one of those control elements and change a setting, then the array will sometimes place that one element at the bottom of the pile.