K-node Posted May 19, 2010 Report Share Posted May 19, 2010 (edited) This question was moved from the Application Design & Architecture forum ( ) as it extended the OT a bit much. So, I have created a Class (call it MyObj) that has refnum to an event held in its private data, the refnum is called MyEvent. The creation of the event uses a strict type def control (call it EventMessage). Each instance of MyObj will have its own event refnum, MyEvent. Here's the rub. Since the events are all created the same way, they have the same name (MyEvent). When I wire the event refnum into the Reg Events vi, I get a collection of the same named entries. Then when I try to handle these events in a Event Structure I get identically named cases (<MyEvent> : User Event), the only way I have been able tell them apart is to add them as cases in the order they were added to the Reg Events. On more than one occasion, the mapping (event instance to case) has gotten mixed up. There are some threads discussing this as well as a NI bug report. Is there a better way to do this? TIA -kugr Edited May 19, 2010 by kugr Quote Link to comment
mje Posted May 19, 2010 Report Share Posted May 19, 2010 On more than one occasion, the mapping (event instance to case) has gotten mixed up. Can you elaborate on this? Is it the coding that gets mixed up or does the event structure itself dispatch the event to the wrong frame? As for distinguishing the events, can you rename the wire via a cast? It's ugly, but might solve the problem of having similarly named frames I'd expect? -m Quote Link to comment
K-node Posted May 19, 2010 Author Report Share Posted May 19, 2010 Can you elaborate on this? Is it the coding that gets mixed up or does the event structure itself dispatch the event to the wrong frame? In my case it is that the event structure that seems to get messed up. The frames have the right code. The event condition that they were originally associated with got switched or removed and replaced by an existing one. I am not sure what caused my remap. I originally thought it was because of the similar names. It may be related to this: http://lavag.org/top...dynamic-events/ At the moment, in my large app, I do have an Event Structure where an event is listed in multiple cases and I know I did not do that. I have not fixed it yet as the project is idle at the moment. As for distinguishing the events, can you rename the wire via a cast? It's ugly, but might solve the problem of having similarly named frames I'd expect? I am OK with ugly if it is the prettiest work around. Thanks! -kugr Quote Link to comment
Jarrod S Posted May 20, 2010 Report Share Posted May 20, 2010 In my case it is that the event structure that seems to get messed up. The frames have the right code. The event condition that they were originally associated with got switched or removed and replaced by an existing one. I am not sure what caused my remap. I originally thought it was because of the similar names. It may be related to this: http://lavag.org/top...dynamic-events/ At the moment, in my large app, I do have an Event Structure where an event is listed in multiple cases and I know I did not do that. I have not fixed it yet as the project is idle at the moment. I am OK with ugly if it is the prettiest work around. Thanks! -kugr You can use the Bundle function to collect your events and give them custom names. There are two equivalent options here: Bundle the events going into the Register Events function so that you have a cluster with three user events. Give each event whatever custom names you want. Wire the whole cluster into the Register Events function. Register each event individually with three Register Event functions. Then wire the three registration refnums into a cluster. Give each registration refnum in the cluster a unique name. Wire the whole cluster directly into the Dynamic Events terminal of the Event Structure. In summary, you can bundle together both events and event registration refnums and everything pretty much just works. Pretty cool! Play around and let us know. Quote Link to comment
MikaelH Posted May 20, 2010 Report Share Posted May 20, 2010 Hi I've never tried using a Cluster into the Dynamic Event Terminal to the Event Structure. So I tried it and it didn't work properly, did I just find a bug... The VIs should switch the Booleans On/Off when mouse enters/leave the controls. But the Cluster Event doesn’t work for button: Hover Over 2 This is in 8.6. The normal way of doing it, which works. Event2.vi Using a cluster It doesn't work. Event1.vi Cheers, Mikael Quote Link to comment
Daklu Posted May 20, 2010 Report Share Posted May 20, 2010 So I tried it and it didn't work properly, did I just find a bug... Looks like it might be a bug with the second RegEvents prim not registering the second event. In your vi Hover Over 2 wasn't firing a Mouse Leave event. When I placed Mouse Leave before Mouse Enter in the RegEvents prim the Mouse Leave event was firing but the Mouse Enter event was not. Breaking those two events out into two separate RegEvents prims made everything work right. (LV2009) Quote Link to comment
K-node Posted May 20, 2010 Author Report Share Posted May 20, 2010 Looks like it might be a bug with the second RegEvents prim not registering the second event. In your vi Hover Over 2 wasn't firing a Mouse Leave event. When I placed Mouse Leave before Mouse Enter in the RegEvents prim the Mouse Leave event was firing but the Mouse Enter event was not. Breaking those two events out into two separate RegEvents prims made everything work right. (LV2009) I think this is what bean was referring to in http://lavag.org/top...n-event-refnum/. See post of May 13th where bean says: "Just make sure you only do one event per Event Registration Refnum when bundling the Event Registration Refnums into a cluster. I originally tried to group "sets" of events this way and revealed a bug. But, the way Ton has displayed will work since he just has 1 event (in this case, user event) per Event Registration Refnum." However this does not seem to be the bug of CAR 148149 (http://zone.ni.com/devzone/cda/tut/p/id/9996#148149_by_Date). Which deals with mapping event to case problems. I could not find anything in my quick scan of the 2009 SP1 known issues. -kugr Quote Link to comment
K-node Posted May 21, 2010 Author Report Share Posted May 21, 2010 OK, to polish my original post off and to help those that might be following along, I attached a project that shows 1) the problem (see Main.vi) where all the events have the same name and the event structure is tought to figure out what is what. 2) a solution as identified by mje (see Main_ViaTypeCast.vi) where we Type Cast the Object's event to an identical Event Refnum, but named differently. 3) a solution as identified by Jarrod S (see Main_ViaRefnumBundle.vi) where we bundle each of the Object's events into a previously created cluster with uniquely named events. 4) a solution also identified by Jarrod S (see Main_ViaRegistrationBundle.vi) where we bundle the Reg Events of each of the Object's events into a previously created cluster with uniquely named Reg Events. I hope that they are clear enough. Post here or PM me if you want. Anyway, I am liking #3 because I do not have to unbundle before I UnregisterForEvents. #2 has a similar feature, but as mje says, it is ugly. Also for you self proclaimed novices, explain to yourself why the EventCode value increments by 2 (as opposed to 1) for each button push. It is pretty obvious when you think about it, but, embarrassingly, it took me by surprise. It was a 'Well Duh' moment - I seem to have those way too often. Have a great weekend! -kugr EventInClass.zip Quote Link to comment
Norm Kirchner Posted June 13, 2010 Report Share Posted June 13, 2010 I am so ecstatic that others are trying to push the process of using dynamic user events w/ objects in with LV and bundling/collecting references, as I've been attempting to do the same for a long time and felt pretty alone That being said I'll toss a minor alternative to the 4 that does not require the use of an explicit typecast. Although the same process, the code gets a little cleaner and w/ some creativity you could VI script some interesting helper VIs to make this easier for you (like burying stuff inside of a sub-vi that the scripting VI's know how to properly edit But the basic premise of this change, is that you use a register event node to properly name everything, and then when it comes time to actually wire in the references, that portion of the code is a bit cleaner. Quote Link to comment
K-node Posted June 14, 2010 Author Report Share Posted June 14, 2010 (edited) I am so ecstatic that others are trying to push the process of using dynamic user events w/ objects in with LV and bundling/collecting references, as I've been attempting to do the same for a long time and felt pretty alone It is how I feel here at work. They have not appreciated the concept of OOP. But the basic premise of this change, is that you use a register event node to properly name everything, and then when it comes time to actually wire in the references, that portion of the code is a bit cleaner. Very nice suggestion. I added this approach to the project, the new vi is called: Main_ViaMultiUserEventRegEvents.vi. EventInClass_v2.zip Edited June 14, 2010 by kugr Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.