From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

callback and user events

Solved!
Go to solution

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

0 Kudos
Message 1 of 5
(3,088 Views)
Solution
Accepted by topic author pawhan11

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).


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 5
(3,077 Views)

Thanks, good to know.

 

0 Kudos
Message 3 of 5
(3,032 Views)

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.

0 Kudos
Message 4 of 5
(3,023 Views)

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.

0 Kudos
Message 5 of 5
(2,955 Views)