Interesting Gotcha with Datagrids

Bob Sneidar bobsneidar at iotecdigital.com
Fri Jan 20 12:45:02 EST 2017


Hi all. 

I just tracked down a nasty gotcha (notice I didn't say 'bug') that can cause a crash to desktop when working with data grids. 

I have (for lack of a better term) a "searchbar" object with all the controls and scripts necessary for filtering a data grid. If you type text into the search field, it saves the dgData and the dgHilitedIndex in properties of the stack. It then sets the dgData of the datagrid to the filtered data, but DOES NOT set the dgHilitedIndex yet. The user does that, and when he does, that is when it gets interesting. 

In the selectionChanged handler of the datagrid I send a mouseUp to the Cancel button of the searchbar object which first resets the searchbar to an initial state, and then RESTORES THE SAVED DATA TO THE DATAGRID! This is where it crashes to desktop. A cookie to the first person who guesses why. 

No? Okay, so the datagrid selectionChanged handler calls a script in another control which then changes the contents of the data grid... WHICH CHANGES THE SELECTION, which of course then triggers selectionChanged... AGAIN. Endless loop. 

The fix for this was simple. Lock messages before I restore the contents of the datagrid. It might be nice however, if there was some kind of message or maybe a crash log that indicated that an endless loop was generated, instead of just crashing to desktop. Just a thot. Thinking about it, this may be the bulk of CTD complaints when using data grids. 

Bob S



More information about the use-livecode mailing list