Dynamic event registration allows you to use VI Server references, such as Application, VI, or Control, to specify at run time the objects for which you want LabVIEW to generate events.
What to Use
Use the following block diagram objects to dynamically register events.
Create the following block diagram to dynamically register the Mouse Enter and Mouse Leave events on a string control.
The following list describes important details about the previous diagram.
Obtain VI Server references to the objects for which you want LabVIEW to generate events. To obtain a control reference constant, like the string control constant from the previous illustration, use a Property Node to query the VI for its controls or right-click the control and select Create�Reference from the shortcut menu.
Use the Register For Events function to dynamically register for events. You can register for multiple events for a single reference by resizing this function and selecting another event. Click the down arrow on the event source input and select the event you want LabVIEW to generate for the reference, such as the Mouse Enter and Mouse Leave events shown in the previous illustration. After registration, LabVIEW queues events as they occur until an Event structure executes to handle the events.
Tip You can view the registered events in the Context Help window when you hover over the event registration refnum.
Right-click the event selector label to display the Edit Events dialog box. Use the dialog box to configure an Event structure to handle a dynamically registered event. The Event Sources section of the dialog box contains a Dynamic subheading that lists each dynamically registered event source. After you select the events you want the Event structure to handle, design the case to handle the event data.
Use the Unregister For Events function to stop event generation. When the Unregister For Events function executes, LabVIEW unregisters all events the event registration refnum specifies, destroys the event queue associated with the event registration refnum, and discards any events that remain in the queue.
Caveats and Recommendations for Dynamically Registering Events
Wire the event registration refnum input of the Register For Events function only when you want to modify an existing registration.
Wire each Event structure that handles dynamic events to a unique Register For Events function. Branching the event registration refnum wire of a Register For Events function allows multiple Event structures to pull events from one queue, resulting in a race condition that may cause unpredictable behavior.