LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

When I split GUI functions over different files, the Panel not in the file with the Main function shows up but does not work.

Hi,

I am have a HUGE (> 69K lines) file full of callbacks that were generated and edited after creating many panels. I decided that the next panel would have its callbacks in another file to keep things reasonably readable. I created the panel in the UIR file, selected my other file for code generation, and let it go. Since there is no way to pick specific functions to generate, I had to generate all callbacks into the other file. I deleted the ones I didn't need that were already in the huge file. The new file had all the necessary headers in it when I generated the code. I added anything I would have needed. I externed all the necessar
y global variables to the new file, compiled and ran the project.

What I got was the panel coming up, the buttons and controls worked, but my callbacks didn't seem to put anything in my externed global variables as they should have.

Any suggestions?

Judy Harrigan
0 Kudos
Message 1 of 4
(2,901 Views)
You said that "there is no way to pick specific functions to generate", but there is, from the UIR editor window.
1. In the UIR editor window, from the Code menu, Set Target File. You can pick an existing file or select (which you can name and save later).
2. Double click on the UIR control for which you need to generate code. Enter the Callback Function name and click OK.
3. Right-click on the control and select Generate Contol Callback.
Here's a few ideas for the rest of your problem.
1. In your UIR editor window, right-click on a control you're having trouble with and select View Control Callback. Verify that the function selected is the one you intend to call.
2. Look closely at how you're using the global variable. Make sure that in your c
allback you're not declaring a local variable with the same name as the global. The way C scopes variables, you can reuse the name of a global variable as a local in a function. When that function returns, the local variable is released and the global is not changed.
3. When you're dealing with separate C files, make sure that the global is declared in a .h file that both .c files have #included and not that each .c files declares it as global to itself.
4. Put a breakpoint in your callback, run the program and operate the control for the callback. Single step through the callback, seeing what code is executed and what the value of the variable is.
Message 2 of 4
(2,901 Views)
P.S.
In larger projects, I typically use a separate C file for each panel. There are then a collection of .h files (including the .h for the UIR file(s) and a .h in which I declare any globals) which I #include in every .c file. It helps me keep larger projects organized and makes it easier to debug and maintain. You do have to make sure you have the right target file selected before you generate code or use Function Panels to insert variables and function calls.
0 Kudos
Message 3 of 4
(2,901 Views)
Hi and thank you,

The information on generating selected callbacks is extremely helpful. I am upgrading old code that lumped all callbacks into one file and I want to stop the madness ;-). I found out why my panel wasn't working. I was incorrectly using the panel constant in the control functions in the new uir file, i.e.

GetCtrlVal(PANEL, PANEL_CONTROL, &value);
(where PANEL is the constant name I entered into the panel information when I created the panel in the uir file)

I should have been using the panel alias generated by the LoadPanel function.

Eg.

in the main uir file:

int panelAlias;

panelAlias = LoadPanel(PANEL, "uirfile.uir", mainpanel);

in the new uir file:

extern int panelAlias;
.
.
GetCtrlVal(panelAlias, PA
NEL_CONTROL, &value);

This worked.

Judy Harrigan
0 Kudos
Message 4 of 4
(2,901 Views)