04-05-2011 12:53 AM - edited 04-05-2011 12:55 AM
In my application I have different panels in single .uir file. When I save the .uir file, I am getting the same #define values for different controls in different panels. Because of this I am not able to use those #defines in switch block. Is it possible to change the #define values as per my requirement.
Solved! Go to Solution.
04-05-2011 01:02 AM
No, it's not possible, because CVI automatically defines a value for every panel and every object in a panel, starting from 1.
You shouldn't edit the .h file because this almost certainly brings to problems.
You can have the #defines modified if you change the Z-plane order of the controls in the uir
04-05-2011 01:07 AM
Hi,
it is the combination of panel and control that is unique, so you also need to check for the correct panel. It is not recommended to touch the UIR include file:
/* WARNING: Do not add to, delete from, or otherwise modify the contents */
/* of this include file. */
Of course, you can also build your panels programmatically, in this case you will define the control_ids yourself.
04-05-2011 03:11 AM
Hi, a little addition to Wolfgang post. It is the combination of panel handle and control ID that is unique: as you may know, you can load the same panel more than once so even if you happen to retrieve the complete string PANEL_CONTROL you have some duplications; the elements that exactly identifies some particular control in some particular panel are the combination of panel handle AND panel_control ID.
On one hand this guarantees more flexibility to your application, since you may design only a few panels and reuse them every time you need, even having some of them loded multiple times in the same moment. On the other hand, as you have discovered, there is the possibility (well, almost the certainty) of duplicated IDs in your application.
To deal with the problem of duplicated IDs you may act two ways:
1. If you know that no panel is never loaded multiple timer in your application you can retrieve the panel constant name with GetPanelAttribute (panelHandle, ATTR_CONSTANT_NAME, string); and discriminate between constant name, then switch between control IDs
2. If you happen to have panels duplicated you need to store each panelHandles in non-volatile variables, switch between them and afterwards switch between control IDs
An alternative could be to use panel callbackData attribute and assign some meaningful value to it when loading the panel, switch between callbackData and finally switch between control IDs. Something like this:
When loading panels:
panelHandle = LoadPanel (0, "myfile.uir", PANEL1);
SetPanelAttribute (panelHandle, ATTR_CALLBACK_DATA, (void *)1); // Assign different callbackData to each instance
When switching between controls:
void *cbkd;
GetPanelAttribute (panelHandle, ATTR_CALLBACK_DATA, &cbkd);
switch ((int)cbkd) {
case 1: // Elements of PANEL1
switch (control) {
case PANEL1_NUMERIC:
// your code here
break;
case PANEL1_STRING:
// your code here
break;
}
break;
case 2:
// .....
break;
}
One final note: it seems to me that all this is necessary in a very limited situation, in which you have the same callback called on different panels/controls. Every time the callback is unique to a specific panel or to controls on a single panel you have no need to operate this way.
04-05-2011 03:30 AM
Hi all,
Thanks for the replies.
Thanks and Regards
NB