LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Panel has identical halves - determine which half callback came from?

Solved!
Go to solution

Hi. I have a panel where the top and bottom halves have the exact same set of controls.  The constant names are also the exact same save for a 1 or 2 appended at the end.  Each identical control in the top and bottom halves perform the same function, and so I was thinking of using a single callback function for both.  The only difference is where the function result gets stored, and that depends on whether the EVEN_COMMIT came from the top or bottom. I am wondering what is the optimal way to program this without having to duplicate code?

 

I was thinking I should probably check which control generated the EVENT_COMMIT (top or bottom) and assign some variable a 0 or 1. I could then use the value of the variable to decide where to store the result of the callback function.

0 Kudos
Message 1 of 4
(3,192 Views)
Solution
Accepted by topic author LeorG

One possible alternative is to assigna a callbackData to the controls on one half and test its presence in the callback function.

 

Assigning the callback can be done this way immediately after loading the panel:

   SetCtrlAttribute (panelHandle, Control_ID, ATTR_CALLBACK_DATA, (void *)1);

 

Testing it in the callback is simply made by:

   if (callbackdata) {

      .....

   }

   else {

      .....

   }

 

Through callbackData you can pass not simply a flag but some value that drives callback behaviour. As an example, if you have an array of data filled with control contents, callbackdata could store the index in the array where to store data.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,186 Views)

Thank you Roberto!

 

About the callbackData , is it possible to attribute a control's ATTR_CALLBACK_DATA with several callbackdata variables?

0 Kudos
Message 3 of 4
(3,179 Views)

callbackData parameter points to a single objet. Nevertheless, you can organize your data into a structure and pass its address into callbackData parameter. The crucial thing is that you are passing and address to an object, and that object must still be valid when the function is executing. That is, you cannot pass the address of local variables or memory areas that have been freed or have a more limited scope. For this reason, either you pass an absolute value (e.g. (void *)1, (void *)2 or similar) or you must be sure that the address passed remains valid when the callback executes (a moment which you cannot say for sure, since it can depend on user actions).

Provided these limitations are satisfied yes, you can pack your data into a structure and route it through callbackData way.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 4
(3,169 Views)