0034930: StringGrid : bug after cell changed by keyboard and then removed

Description

A cell receive a keyboard input (e.g : text erased), and then grid.rowcount is set to a lower value, there is later an exception trying to get text from the no more existing cell.

Steps To Reproduce

1) Run the attached program.
2) Click on the button in the main form : a grid with 2 rows is displayed.
3) Select the cell in the second row
4) Erase it's content with the keyboard (Delete key or Backspace). Do not use the Delete Button.
5) The second form is closed. The program saves only non blank cells.
6) Click again on the button
7) An exception occurs, trying to read the cell [1,0] which do not exists anymore. Only one row should be displayed and accessed. Check the call stack.

You can check that when the 2nd row is deleted using the "Delete" button, or when nothing is deleted, there is no problem.

The problem also is related to the fact that you show Form2 modally. If I use Form2.Show (instead of Form2.ShowModal) and use an OnClose event to call Save_Grid everything work fine, too, even if goAlwaysShowEditor is active all the time:

However it is important to find a way to fix the problem which was not existing in earlier versions, before version 1.8, I think.

When we try to upgrade an application with a newer version of Lazarus, the problem makes many new bugs to occur only in specific circumstances and not detected during tests. Doesn't help us to make quality software !

"DeleteRow" correctly hides the editor, if it was on the removed row.
Setting RowCount now does the same (for rows removed).

--
Note:
As for your particular case: You may consider always hiding the editor when the form is closed. Otherwise the editors content may be saved to the cell, when you start writing to cells from your saved data. (May be no harm in it, ...)
For discussions on this note, please use the forum only.