LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

can not save panel state

I use below code (OK button) to save the changing on the panel during I run the CVI app.
 
int CVICALLBACK Button_Config_Test_Ok (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:
       // Save State of Panel
    SavePanelState (panel, g_szTesterConfigFileName, TEST_CONFIG_PANEL_SAVE_INDEX);
    DiscardPanel(panel);
   break;
  }
 return 0;
}
 
But after I press the OK button, the changing on this panel can not be changed, it remains one state every time.
 
I know I change this panel in the uir file, the problem is I use   SavePanelState, but I don't know how to let the OK button works?
 
Hope veteran can help me.
 
Crystal
0 Kudos
Message 1 of 5
(3,643 Views)
Hi Crystal,
I think I didn't get you right.
1) Why do you discard the saved panel?
2) It's "dangerous" to discard a panel within a callback function running on the panel. Is that what you want, what you really really want?
BR
0 Kudos
Message 2 of 5
(3,634 Views)

Hi dilution,

My app problem is firstly, I edit my test config panel in uir ,then I debug the app, the error is the control value could not be completely loaded into the panel because the panel has been changed. I know it is the problem that I use SavePanelState or RecalPanelSate function in my app. So I try to remark the RecallPanelState code line with //, but I am not sure. What do you think what should I do at that time?

Second, after I save the uir, I cancelled the remark with the RecallPanelState code line, so the above error doesn't happen again.

From your suggestion I know it is wrong to disard the RecallPanelState inside the Callback loop. Could you help me what is the right and safety solution, when I met this kind of error again. Thanks.

CrystalSmiley Surprised

0 Kudos
Message 3 of 5
(3,619 Views)
Hi Crystal,

1) Saving Panel State:
- SavePanelState creates a real file on your hard drive. The values of control are stored in the file. I used it like this:
if ((err = SavePanelState (panel,"PanelSaved.sav",1))<0)
    {
     MessageBeep(MB_ICONEXCLAMATION); //needs #include <windows.h> 
     MessagePopup ("Save ILL SEC 1 Panel", GetUILErrorString (err));
    }
- To recall the saved file if the file exists (otherwise, it does nothing):
if ((panelHandle = LoadPanel (0, "Panel.uir",PANEL)) < 0)
        return -1;
SetBreakOnLibraryErrors (0);
RecallPanelState(panelHandle,"PanelSaved.sav",1);
SetBreakOnLibraryErrors (1);
- If you change the uir file "manually" (i.e. in the CVI IDE, adding or removing a control), you just have to delete manually the .sav file.

2) Closing an panel:
- A simple rule is to discard the panel where it has been loaded. In the main{} in simple cases. Otherwise, you have panel handles handling nothing. It is not a huge problem in the sense that panel handles are nothing more than integer. The problem is: how do you now that the handle is handling something? Do you have a structure whose pointer is known everywhere to manage that?
- In the previous exemple, I would discard the panel where the int panelHandle is known:
DiscardPanel(panelHandle);
panelHandle = -1; //Negative value tells me that there is no panel associated to the handle.

BR

   
Message 4 of 5
(3,607 Views)

Hi Dilution,

Thanks for your explanation. It is highly appreciated.

BR

 

0 Kudos
Message 5 of 5
(3,596 Views)