LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

invalid control id plague

I have a pretty simple application and I am getting several "Invalid control ID" non-fatal errors that I am having difficulty understanding.  I have only one panel, and I am addressing the panel correctly, I am using the helper to select the control, and I am using the control no problem, but, when I exit, I get the error.  Why is this?  It is happening with LED's numeric control, and tables, so far.  They work, until I exit the application.
0 Kudos
Message 1 of 12
(5,143 Views)

What version of CVI are you using?

Have you debugged your program by stepping through it to see which line is causing the problem?

Do you start your UI with RunUserInterface and end it with QuitUserInterface?

What do you do before exiting?

Are you trying to access any controls after discarding the panel or calling QuitUserInterface?

Can you post your exiting code (anything after RunUserInterface)?

0 Kudos
Message 2 of 12
(5,125 Views)
I am using Labwindows CVI 8.0

I am seeing which lines cause the problem, puzzlingly, the code uses those lines many times with no problems, only when I exit do I get the exceptions.

Yes, I start and quit the UI as you describe in your question.

The only command executed when exiting is QuitUserInterface(0);

I do not attempt anything after QuitUserInterface(0);

Exiting code:

void CVICALLBACK ProgramQuit (int menuBar, int menuItem, void *callbackData,
        int panel)
{
 
  QuitUserInterface (0);      
}


here is my main:

int main (int argc, char *argv[])
{

    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
    if ((specpanelHandle = LoadPanel (0, "Spectralyzer Main.uir", SpecPanel)) < 0)
        return -1;
   
    Initialize();
    Update_Graph();
    x_axis_scaling_mode=VAL_MANUAL;
    y_axis_scaling_mode=VAL_MANUAL;
    DisplayPanel (specpanelHandle);
    RunUserInterface ();
    DiscardPanel (specpanelHandle);
    return 0;
}


Thanks,


0 Kudos
Message 3 of 12
(5,120 Views)

So what line of code causes the problem?

I don't see anything that would obviously cause your problem.  One thing I would suggest is to check for EVENT_COMMIT before calling QuitUserInterface().  Multiple events (e.g. EVENT_GOT_FOCUS, EVENT_LEFT_CLICK, EVENT_COMMIT) will fire for a click on Quit.  You only need to call QuitUserInterface once, for EVENT_COMMIT. 

I also don't recognize the prototype for your ProgramQuit function.  Try the following.

int CVICALLBACK ProgramQuit (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)

{
 switch (event)
  {
  case EVENT_COMMIT:
   QuitUserInterface (0);
   break;
  }
 return 0;
}

0 Kudos
Message 4 of 12
(5,115 Views)
This is an example of one of the lines causing the problem.  Note, it works just fine, until quit:

    SetTableCellVal(specpanelHandle,SpecPanel_CursorTable,MakePoint(2,5),delta_cursor_2_3_y);


I will try your quitting strategy.

Thanks,


0 Kudos
Message 5 of 12
(5,112 Views)
I am quitting using the menu.  I added a command button just like you show, same thing happens.
0 Kudos
Message 6 of 12
(5,109 Views)
So SetTableCellVal gets called when you click Quit?
 
In what callback is that call to SetTableCellVal?
In that callback, do you check for EVENT_COMMIT?  If not, it might be getting called on EVENT_LOST_FOCUS, which you probably don't want to do.
0 Kudos
Message 7 of 12
(5,107 Views)
It is in an function that is not a callback that I use to update my graph.  It is one that I added, it is a function is called by others, including main().

Maybe I do not really understand the sequence very well.

It seems that this function is entered when quitting.  Some SetCtrlVal and like functions work, others do not.

Stepping through, it seems that other call back functions are entered as well. Why is this?  Why not just quit?

Program seems to work fine, just is not quitting cleanly.
0 Kudos
Message 8 of 12
(5,104 Views)

Several different events may be fired for controls other than the one clicked on.  You should always check for EVENT_COMMIT before executing your code.

The event that may be causing you the most problem is EVENT_DISCARD which is sent to panels and controls when they are discarded.

Double check that all your callbacks (including but not limited to callbacks that call your update function) check for EVENT_COMMIT.

0 Kudos
Message 9 of 12
(5,096 Views)

Hello,

The problem you are facing could be that you placed a line of code at the wrong place in a function. For example, the code below would run correctly but give you the exact warning you are talking about when you exit:

int CVICALLBACK RangePrint (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
    char CellRangeValue[10]={"\0"};

    GetCtrlVal(panelHandle, PANEL_MYCELLRANGE, CellRangeValue);  //code works but gives error when you exit.

    switch (event)
    {
        case EVENT_COMMIT:
           ExcelRpt_RangePrint (ExcelWorksheetHandle, CellRangeValue, 1);//works in Excel sheets only (not Excel ActiveX).

           break;
        case EVENT_RIGHT_CLICK:

        break;
    }
    return 0;
}

To solve the problem above, remove the highlighted code above and place it at location shown below:

 

int CVICALLBACK RangePrint (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
    char CellRangeValue[10]={"\0"};

    switch (event)
    {
        case EVENT_COMMIT:
           GetCtrlVal(panelHandle, PANEL_MYCELLRANGE, CellRangeValue);  //code would run and exit without errors.
           ExcelRpt_RangePrint (ExcelWorksheetHandle, CellRangeValue, 1);//works in Excel sheets only (not Excel ActiveX).

           break;
        case EVENT_RIGHT_CLICK:

        break;
    }
    return 0;
}

Please search your code for errors like this, correct it and let me know of the out come.

Robert Mensah (Test Engineer)

0 Kudos
Message 10 of 12
(5,088 Views)