LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

InsertTreeItem problem

Hi!

I want to create a Tree dynamically. The methods are listed below. The first one works, but when I try to add items using the second method, my program crashes.

NON-FATAL RUN-TIME ERROR:   "CommView.c", line 60, col 13, thread id 0x00000A60:   Library function error (return value == -14 [0xfffffff2]). Value is invalid or out of range

All items that are added by the second method must be the child of the first element, the one that are added by the first method. What is it wrong? I would like to show checkboxes for the elements that are added by the second method, but I don't know how.

Thank you!

int intTreeIndex = 0;
void listDataSource ( int intDSPanelHandle, int intDSControlHandle, char *chrBufferProviderList ) {
    
        InsertTreeItem(intDSPanelHandle, p_intDSControlHandle, VAL_SIBLING, g_intTreeIndex, VAL_NEXT,
            chrBufferProviderList, 0, 0, g_intTreeIndex);
        intTreeIndex = intTreeIndex + 1;
  
    return;
}

void DSV_listDataSourceParameters (int intDSPanelHandle, int intDSControlHandle, char *chrOutParameterList) {
    
    char *Tok;

    Tok = strtok(m_chrOutParameterList, ",");
        
    while (m_chrTok != NULL) {
        // Anda
        if ( g_intTreeIndex  == 1 ) {
            InsertTreeItem(p_intDSPanelHandle, intDSControlHandle, VAL_CHILD, intTreeIndex, VAL_NEXT,
                Tok, 0, 0, intTreeIndex);
        }
            else {
                 InsertTreeItem(p_intDSPanelHandle, intDSControlHandle, VAL_SIBLING, intTreeIndex, VAL_NEXT,
                    Tok, 0, 0, intTreeIndex);
            }
        intTreeIndex = intTreeIndex + 1;
        Tok = strtok(NULL,",");
    }
    
    return;
}

0 Kudos
Message 1 of 2
(3,547 Views)
Hi,

I think you use the same TreeIndex for the whole function.
You use the indexes in a wrong way.

First of all, I think the tree index is 0-based.

So if you use your item index for the relative index, the child item use a relative index with a value equal to 1 (should be 0 for the first item).
Then you insert the item with a sibling relation and a relative index equal to 2 (should be 0).
The next items should use an incremental relative index.

The global item index cannot be used for the relative index. You should define a new index.

Here is the code that works for me :

    int childTreeIndex = 0;  /* relative item index for the items inserted with a sibling relation   */

    Tok = strtok(chrOutParameterList, ",");
        
    while (Tok != NULL) {
        // Anda
        if ( g_intTreeIndex  == 1 )
        {
            InsertTreeItem(intDSPanelHandle, intDSControlHandle, VAL_CHILD, 0 /* The item index is 0-based */, VAL_NEXT,
                Tok, 0, 0, g_intTreeIndex /* your incremental item value */);
        }
        else
        {
            InsertTreeItem(intDSPanelHandle, intDSControlHandle, VAL_SIBLING, childTreeIndex++ /* incremental relative index */, VAL_NEXT,
                    Tok, 0, 0, g_intTreeIndex /* your incremental item value */);
            
        }
        
        g_intTreeIndex = g_intTreeIndex + 1;
        Tok = strtok(NULL,",");
    }



Another way to do that :
You can do it in a easier way, without relative index.

    Tok = strtok(chrOutParameterList, ",");
       
    while (Tok != NULL) {
        // Anda
        if ( g_intTreeIndex  == 0 )
        {
            InsertTreeItem (intDSPanelHandle, intDSControlHandle, VAL_CHILD, 0,
                            VAL_FIRST, Tok, 0, 0, g_intTreeIndex);
        }
        else
        {
            InsertTreeItem (intDSPanelHandle, intDSControlHandle, VAL_SIBLING, 0 /* The relative index is always 0 */,
                            VAL_LAST /* You insert the item at the end */ , Tok, 0, 0, g_intTreeIndex);
           
        }
       
        g_intTreeIndex = g_intTreeIndex + 1;
        Tok = strtok(NULL,",");



Hope this help.
Bruno
Message 2 of 2
(3,530 Views)