LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Link between panel handle and panel constant

Hi.
Which is the link between the panel handle returned by LoadPane and the related panel constant that is defined in the relevant .h file after saving the .uir?
What happens to me is that after playing with the user interface adding and removing panels, I get runtime errors like "invalid control ID" unless I load the panels in such a way so the handles are numerically equal to the panel ID constant defined in the .h file. Moreover, it happens that calling LoadPanel to load the different panels, the handles are not subsequently numbered but for instance I get 1, 2, 3 and then 5, 6, 7, so missing 4. Actually I have only 6 panels and their constant ID are numbered in the .h file from 1 to 6. I get the runtime error the first time I attempt to access to the fourth panel, which has a constant ID =4 but an handle =5. Note that even if I delete the .h file so that saving the .uir a new one is created, the problem is not solved.

Now, I can fix this behaviour by introducing another panel named so that it is alphabetically placed in the .h file with a ID =4. In this way I get the correspondence between handles and ID by loading the panels in the same order as they are defined in the .h file and everything works.

Does anyone have an explanation about it ?

Many thanks in advance,
Enrico
0 Kudos
Message 1 of 3
(3,157 Views)
Hi Enrico,

there is absolutely no connection between the panel handle and the paneo resource ID defined in UIR file. You can load the panels in memory during program execution regardless of the order in which they are stored in the include file (moreover, you are not compelled at all to load all panels in memory during program starting, and you could even load a panel more than once and provided you store their handles in different variables each panel has an indipendent life and can be used/moved/addressed/discarded indipendently)

The concept to the basis of the mechanism is this one: when you load a panel in memory you assign a handle to that particular window, which holds some controls on it. Now, the resource is loaded in memory addressing it among all the resources that actually are present in a UIR file by the Panel Resource ID passed to LoadPanel function.This resource once loaded in memory is assigned a unique handle that is the return code from LoadPanel. This handle must be stored in a variable and used in all subsequent operations on the panel itself or on controls that lie on it.

When you operate on the panel, you must use its handle (not the resource ID!) to identify that particular istance in memory.

When you operate on the controls, you pass to SetCtrlVal or other function the panel handle and the control resource id, that is you manipulate the i-th control on the resource that is loaded in memory and identified by that handle.

SetCtrlVal has no interaction with the UIR and H file generated by the UIR editor, and addresses controls via their index inside the panel. What can be happening is that you are someway using wrong panel handles to operate on controls: if for example the 3rd control on one panel is a string and the 3rd control on a second panel is a numeric, exchanging panel handles let the "Invalid control ID" error arise, 'cause you are passing a double to a control that accepts only chars.

OK, resuming: load in memory all and only the panels you do need in some moment; store the return value from LoadPanel in (global) variables; pass this variables to SetCtrlVal and other functions to manipulate controls on that panel. This way the Invalid control ID error won't arise any more.


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 2 of 3
(3,154 Views)
OK Roberto,
I am really ashamed of my question! This is the kind of things that happen when the weather is hot and while programming late in the evening.
Your explaination is just as I figured out things have to go, but I was not able to see the mistake. So, I erroneously used the resource ID instead of the panel handle while writing a function call, then I made other calls just doing copy and paste and eventually I got completely confused.
Many thanks for having switch-on my light again !
Sincerely,
Enrico
0 Kudos
Message 3 of 3
(3,147 Views)