Hello,

Should Fl_Menu_Item::next() return NULL when the end of the menu item list
is reached? If so, it doesn't for me.

I populate a Fl_Choice using a for-loop and Fl_Choice::add(). The label for
the item is a malloc'd string using strdup(). When the user has selected a
choice, I want to do the clean-up by free'ing the strdup'd strings.

To do the clean I I do:

Fl_Menu_Item *item = const_cast<Fl_Menu_Item*>(menu->menu());

while(item)
{
        free((void*)item->text);
        item->text = 0;

        item = item->next(1);
}

I throw away the constness of menu->menu() since I need to modify the text
field.

It appears the "item = item->next(1);" never returns NULL. Instead, with
kdevelop's debugger, I see a valid item being returned but the text field
is 0. So, as a workaround, I made the while-condition:

while(item && item->text)
{....

I know I should construct a static FL_Menu_Item array, but it was quicker to
code it up using add(). Oh, and the reason I need to strdup() the string is
my source strings (string provided by another library) may contain '/' as a
delimiter but not intended to delimit the menu. I replace all occurrences
of '/' with '-'.

-- 
Alvin
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to