Hi,
I have a function called make_browserlist as follows:
I can call this with static STRPTR string data and populate my listbrowsers fine.
However, I want to use char[] arrays that have strings I have retrieved from an input text file to populate my listbrowser lists using this same function.
I suspect I need to coerce my character arrays into static strings somehow. When I try to pass my char arrays into this function I always seem to get DSI errors no matter what I do. So for example I might do the following:
I am retrieving mylist using basic C fileio and verifying that the string data is actually populated in mylist.
Does mylist have to be global? I have tried calling make_browserlist with (char *)&mylist etc but always get the same result.
Thanks!
BOOL make_browserlist(struct List *list, char **tagstring, int columns) { struct Node *node; IExec->NewList(list); switch (columns) { case 2: while (*tagstring) { if (node = IListBrowser->AllocListBrowserNode(columns, LBNA_Column, 0, LBNCA_Text, *tagstring++, LBNA_Column, 1, LBNCA_Text, *tagstring++, TAG_DONE)) { IExec->AddTail(list, node); } else { IDOS->Printf(" AllocListBrowserNode() failed\n"); return(FALSE); } } case 3: while (*tagstring) { if (node = IListBrowser->AllocListBrowserNode(columns, LBNA_Column, 0, LBNCA_Text, *tagstring++, LBNA_Column, 1, LBNCA_Text, *tagstring++, LBNA_Column, 2, LBNCA_Text, *tagstring++, TAG_DONE)) { IExec->AddTail(list, node); } else { IDOS->Printf(" AllocListBrowserNode() failed\n"); return(FALSE); } } case 5: while (*tagstring) { if (node = IListBrowser->AllocListBrowserNode(columns, LBNA_Column, 0, LBNCA_Text, *tagstring++, LBNA_Column, 1, LBNCA_Text, *tagstring++, LBNA_Column, 2, LBNCA_Text, *tagstring++, LBNA_Column, 3, LBNCA_Text, *tagstring++, LBNA_Column, 4, LBNCA_Text, *tagstring++, TAG_DONE)) { IExec->AddTail(list, node); } else { IDOS->Printf(" AllocListBrowserNode() failed\n"); return(FALSE); } } break; default: IDOS->Printf(" Invalid number of list fields\n"); return(FALSE); }; // switch return(TRUE); }
char mylist[1000]; ... if(make_browserlist(&listbrowser_list1, mylist, 3) { // list made okay - continue with program } else { IDOS-Printf("Error making browser list!\n"); }
IIntuition->SetAttrs(OBJ(OBJ_LISTBROWSER1), LISTBROWSER_Labels, NULL, TAG_DONE);
SetGadgetAttrs() and RefreshSetGadgetAttrs(), on the other hand, expect their first argument to be a struct Gadget pointer (instead of an Object pointer) so the type cast is appropriate. In your particular example, not much harm will be done but be careful about unnecessary type casting, it may cause trouble elsewhere.