Use dynamic registration if you want event generation to occur during only part of the application or if you want to change which VIs or controls generate events while the application is running. With dynamic registration, you can handle events in a subVI rather than only in the VI where the events are generated.
Complete the following steps to dynamically register an event.
- Place the Register For Events function on the block diagram.
- Wire a reference to an application, VI, control, or user event to the event source input of the Register For Events function.
- Click the down arrow on the event source input and select the event you want LabVIEW to generate for the reference, such as Value Change, Key Down, Key Up, and so on. The event source input label changes from Event to the event you choose from the shortcut menu. You can register multiple events for a single reference by resizing the Register For Events function and selecting another event. Event sources that generate only one kind of event, such as User Event for a user event, automatically select that event.
- Place a While Loop on the block diagram to the right of the Register For Events function.
- Place an Event structure inside the While Loop.
- Right-click the border of the Event structure and select Show Dynamic Event Terminals from the shortcut menu.
- Wire the event reg refnum out terminal of the Register For Events function to the dynamic event terminal on the left side of the Event structure.
- Use the Edit Events dialog box to configure a case in the Event structure to handle the event.
- Place the Unregister For Events function on the block diagram to the right of the Event structure outside the While Loop.
- Wire the dynamic event terminal on the right side of the Event structure to the event registration refnum input of the Unregister For Events function.
- Edit a case in the Event structure to handle the dynamically registered event.
Follow this sequence to complete the basic steps necessary to use dynamic registration with the Event structure. A more complex application might require you to move sections of this sequence into subVIs, register
for different sets of events simultaneously, and so on.
Refer to the labview\examples\general\dynamicevents.llb for examples of dynamically registering events.