07-31-2015 05:49 AM
Hello,
I am developing some UI and in my case I will have many controlls that will respond to the same events. One approach is to make array of refs and use events to handle all of them.
My other idea was to use callbacks instead of user events. But there is some unexpected behavoiur when i register callback for labview controll. Code inside user evend and callback is the same but using callback causes LV to stop responding.
Is there some fundamental mistake that I make in callback approach? Could someone please explain that?
Example in attachment
Solved! Go to Solution.
07-31-2015 06:02 AM
The user event solution with an array of references would be my preferred solution. It's not recommended practice by NI to use callbacks for front panel events even though it can be done because it obscures the event handling code (look at the help for register callback).
07-31-2015 08:05 AM
Thanks, good to know.
07-31-2015 08:26 AM
Is there a reason you didn't want to use the event structure and registering for references option? Or were you just trying to be smart?
One thing people don't always like is having to make control references for every control one at a time (or in groups in newer versions of LabVIEW) then having to wire each scalar reference into a build array. There are alternatives to this method, like using the Traverse For GObjects or the Find Object by Label (in the vi.lib on the palette with Hidden Gems package). This way you can get references based on the string label, and with a little work you can get all references which match a string pattern, or use an array of string specifying all control names. Then register with these returned references.
I try not to over use this feature because it can be confusing trying to debug behavior of UI elements, and choosing the Find >> References won't return anything because get those references by using other references.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
07-31-2015 03:43 PM
I wanted to try that mostly out of couriosity.
I wanted to try if there is a way to separate defining UI controll behavior from main loops. To make some functionalities reusable for future, without having to add the same event cases into events in each subpanel.
I have seen approach where people spawn handler that defines functionality of controll, but handler is an loop and needs communication mechanism.
I was thinking about doing the same using callback because I only need to define and forget.