This weeks nugget is about dynamic events, the way to use them and how we could use them.
First about the
event structure:
Basically the event structure is a piece off code that doesn't follow dataflow rules.
When it is executed, LabVIEW waits on an event and then performs the action specified in that event-case.
Normally these events are user based, like keyboard actions (up, down), mouse action (up, down, move).
Event based programming can be tricky but it is usefull to get the event structure 'in your fingers'.
Dynamic event registration allows you to turn (parts) of your events on and off.
Let's say you have a program that allows you to set points in a picture control. Like a pixel colorizer in Paintbrush
With
polling it looks like this:

(don't run this code! it has no correction for position of the Picture control or even a delay on the while loop)
With an event case the code looks like this:

With some additional events like mouse-down and some status control we can skip the mouse-device VI's.
But it means the 'Mouse Move' event is triggered
every time the user moves the mouse inside the picture control and can cause an overhead on the program.
Dynamic events allow you to turn the events on and off so the event only activates when the user has the left mouse button down inside the picture control (or part of that control).
See this:

The actual event that colorizes the pixel [0] is initially referenced to a static non existing 'Ref constant', but it will become active when the mouse is going down (eventcase [2])* and is turned off again if the mouse button is released or the mouse moves out of the picture control.
With dynamic events you have a very powerfull tool to
manage your event node! And
reduce calls to your event node.
You can pass the the event refence into subVIs and even
Action Engines,
but be aware that you can best store them in a strict type def control
since the data type must be preserved!
To have a look in which direction event nodes are going I advice some study on XControls.
A list of all Nuggets can be found here.
If you have a Nugget you would like to present please post here to reserve your week!
I'd like to thank Darren for his effort into starting the nuggets!
My thanks to Ben is expressed by using the picture control 
Ton
* Notice that I don't check which button is down! This should be a next improvement
Message Edited by TonP on 04-17-2007 10:38 PM