Carl Ding wrote:
> The problem is when I delete a row, I use Fl::delete_widget to remove
> all the embedded widgets in that row. The program crashed when doing
> fl_draw(). Is there anything else should be done to remove a row from 
> Fl_Table?

        Tell Fl_Table there's one less row by setting Fl_Table::rows(val),
        e.g.:

                if ( table.rows() > 0 )
                     table.rows(table.rows() - 1);

        Fl_Table doesn't have a 'delete row' function because it doesn't
        maintain any data of its own, so there's nothing to 'delete'.

        It's just a space managing template that uses the rows() and
        cols() values you tell it, and it just calls your draw method
        once for each of the cells in all the rows and columns it knows
        about.

        When you delete a row of your data, you have to tell Fl_Table
        there's one less row to draw, otherwise your draw function will
        crash when Fl_Table calls it to draw data for that last row that
        no longer exists.

        Fl_Table is analogous to the 'for()' loop in the following:

                for ( int row=0; row<rows; row++ )
                    printf("%d) %f\n", row, data[row]);

        ..where the 'for' loop is Fl_Table, and the printf() is your draw
        routine, and data[] is your own data; Fl_Table is just the loop,
        it knows nothing about the printf() or your array of data.. it just
        knows to call your printf() once for all of the 'rows'.

        So if you decide to realloc() the data[] array to be smaller,
        but don't decrement 'rows', your printf() will crash printing
        the last element because the data is no longer there. Decrementing
        'rows' when you resize the array would be the same as decrementing
        the Fl_Table::rows() value.
        
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to