LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to determine if panel controls have been edited

Have a panel with several control and text fields. There is an 'OK' button on the panel which will initiate various actions.
Is there a simple method to determine if any of the controls and text fields etc. have been modified so that  the 'various actions' might be easily skipped  ?
 
0 Kudos
Message 1 of 7
(3,922 Views)

Hello Ablade,

The following lines deal with your concern. This example shows you the "Callback function" functionning. A callback function is called when an event occurs for any panel/menu bar/control of your front panel. Defining a callback function is done by double clicking on a control and filling the "Callback function" field. (please refer to the attached image for visual details)

After having complted this first step, right click the control and select "Generate control callback" so that the following code is added to your .c file:


int CVICALLBACK ChannelSelectionChange (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
/* Enter your code here */

....... 

return 0;
}


What I suggest you is to check if the value of the control value has been changed, and according to this test, change a boolean flag meaning that the value has been changed by the user. It could allow you to skip your various actions consecutive to the 'OK' button press.

This was just a very first explanation about "Callback functions". For more information, please take a look in the CVI help, there is a section named "Using Callback Functions to Respond to User Interface Events"

Hope this helps

Best regards,

Message Edité par Mathieu Steiner le 08-17-2006 02:37 AM

Message 2 of 7
(3,918 Views)
Thanks for that Mathieu,

I was wondering if the scenario was possible without having to place checking code in each of the control callbacks. ie. In the OK button callback by checking some flag that may exist for the entire panel indicating that ANY of the controls had been edited/modified. I guess my question comes down to does such a predefined flag exist on a per panel basis ?

A.
0 Kudos
Message 3 of 7
(3,888 Views)
No, it doesn't.  think about it... if it did exist, and something had changed, then you would have to go "do all that work" anyway to see what changed.
0 Kudos
Message 4 of 7
(3,872 Views)

If you need a single set  of flags you can probably add that to your application without too much effort.  Most controls generate an EVENT_VAL_CHANGED event, from the cvi help file:

The EVENT_VAL_CHANGED event is generated continuously while the user is performing an ongoing action which results in the value of a control changing. Examples of these actions are: operating the up/down arrows of a numeric control, a ring control, or a table cell; holding the left mouse button down while selecting different items of a list box control; dragging a graph control cursor.

If your controls do not already have an assigned callback function you could use a single callback for all of them and use a switch (control) statement to decode which control had been changed within the callback.  You can then update a list of flags or what ever other mechanism you need to detect when a control has been changed.

Even if some controls do have a callback assigned, you can still trap EVENT_VAL_CHANGED and set your flags as needed.

Good Luck

 

Message 5 of 7
(3,869 Views)

Hello all,

Here is another possible solution.

This solution requires only one callback function (the one of 'OK' button). In this callback function, you could test if your controls actual values are the default ones... So that for each control:

1. GetCtrlVal( MyPanelHandle , PANEL_CTRL , MyControlValue);  // Get actual value

2. GetCtrlAttribute( MyPanelHandle, PANEL_CTRL, ATTR_DFLT_VALUE, MyControlDefaultValue);  // Get control default value

3. if( MyControlValue == MyDefaultControlValue)

                // Go on with remaining controls

    else

               // At least one control has been changed

 

Note:

* Default value can be defined in the .uir file or programmaticaly using SetCtrlAttribute( ... , ... , ATTR_DFLT_VALUE, MyDefaultValue);

* This solution will work for the controls that accept a default value (Control Types:  Numeric, Color Numeric, Numeric Slide, String, Text Message, Text Box, Command Button, Picture Button, Toggle Button, Text Button, Radio Button, LED, Binary Switch, Ring, Ring Slide, Picture Ring, List, Tree)

Hope this helps. Please keep us informed

Best regards,

 

Message Edité par Mathieu Steiner le 08-18-2006 09:03 AM

Message Edité par Mathieu Steiner le 08-18-2006 09:03 AM

0 Kudos
Message 6 of 7
(3,856 Views)

That method works, but it does have a caveat:

It will only work for the first time a value is changed.  If the panel is brought up a second time (if that is possible/applicable), then any value that was changed the previous time would still show up as being changed this time.  If you are only looking for values that had been changed on this invocation, it wouldn't work.

Guess I don't see why someone would want to re-invent the wheel by bypassing callbacks.  They self generate fromt he GUI and aren't very big, so time/size constraints aren't really there.......

0 Kudos
Message 7 of 7
(3,844 Views)