View Issue Details

IDProjectCategoryView StatusLast Update
0034930LazarusLCLpublic2019-01-25 18:38
Reportertintinux Assigned ToMartin Friebe  
Status resolvedResolutionfixed 
Platformx86OSWindows and Linux 
Product Version2.1 (SVN) 
Target Version2.2Fixed in Version2.2 
Summary0034930: StringGrid : bug after cell changed by keyboard and then removed
DescriptionA 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 Reproduce1) 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.

Additional InformationOccurs with version 1.8.4 as well as 2.1 trunk.
TagsNo tags attached.
Fixed in Revision60217
Attached Files



2019-01-22 14:17



2019-01-22 20:42

developer   ~0113586

Last edited: 2019-01-22 21:03

View 4 revisions

You have option goAlwaysShowEditor activated, this means that the grid never leaves EditorMode. When I turn this off the problem is gone.

If you insist on the AlwaysShowEditor feature you could turn OFF the option in the object inspector and in the FormClose event, and turn it ON in the FormShowEvent:

  procedure TForm2.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    Grid.Options := Grid.Options - [goAlwaysShowEditor];

  procedure TForm2.FormShow(Sender: TObject);
    Grid.Options := Grid.Options + [goAlwaysShowEditor];

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:

  procedure TForm1.Form2Close(Sender: TObject; var CloseAction: TCloseAction);

  procedure TForm1.Button1Click(Sender: TObject);
    Form2.Read_grid ( Data );
    Form2.OnClose := @Form2Close;


2019-01-25 09:42

reporter   ~0113614

Thanks for the workaround !

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 !

Martin Friebe

2019-01-25 18:38

manager   ~0113621

Fixed in r60217

Please test and close if ok.

Decision on merging to 2.0 is pending, hence target 2.2 for now.

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

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.

Issue History

Date Modified Username Field Change
2019-01-22 14:17 tintinux New Issue
2019-01-22 14:17 tintinux File Added:
2019-01-22 20:42 wp Note Added: 0113586
2019-01-22 21:02 wp Note Edited: 0113586 View Revisions
2019-01-22 21:02 wp Note Edited: 0113586 View Revisions
2019-01-22 21:03 wp Note Edited: 0113586 View Revisions
2019-01-25 09:42 tintinux Note Added: 0113614
2019-01-25 18:28 Martin Friebe Assigned To => Martin Friebe
2019-01-25 18:28 Martin Friebe Status new => assigned
2019-01-25 18:38 Martin Friebe Fixed in Revision => 60217
2019-01-25 18:38 Martin Friebe LazTarget => 2.2
2019-01-25 18:38 Martin Friebe Widgetset GTK 2, Win32/Win64 =>
2019-01-25 18:38 Martin Friebe Note Added: 0113621
2019-01-25 18:38 Martin Friebe Status assigned => resolved
2019-01-25 18:38 Martin Friebe Fixed in Version => 2.2
2019-01-25 18:38 Martin Friebe Resolution open => fixed
2019-01-25 18:38 Martin Friebe Target Version => 2.2