取消
显示结果 
搜索替代 
您的意思是: 

callback and user events

已解决!
转到解答

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 项奖励
1 条消息(共 5 条)
3,943 次查看
解答
已被主题作者 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 项奖励
2 条消息(共 5 条)
3,932 次查看

Thanks, good to know.

 

0 项奖励
3 条消息(共 5 条)
3,887 次查看

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 项奖励
4 条消息(共 5 条)
3,878 次查看

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 项奖励
5 条消息(共 5 条)
3,810 次查看