Recent

Author Topic: TStringGrid : Conflict between "OnEditingDone" and "Columns.Clear"  (Read 1950 times)

Nel_Fie

  • New Member
  • *
  • Posts: 15
Re: TStringGrid : Conflict between "OnEditingDone" and "Columns.Clear"
« Reply #15 on: May 19, 2023, 06:37:05 pm »
I understand now what you want to achieve. Quite complex...

Maybe rather than rebuilding the json and the grid after each editingdone you should prepare columns for all allowed attributes and hide them initially (Grid.Columns[index].Visible := false) except for the NAME column. Then, once the user has entered a string in this column, the CLASS will be uncovered. And when the user has selected a value in this cell the attribute columns compatibile with this CLASS will appear. This way the user always sees where values can be entered and there is no chance that he can destroy the logical connections between the cells.

Yes, that's roughly what I was thinking as well, at this point. I'd assume data in hidden columns would still be accessible, so that would avoid any mishaps when collecting data to store.

I'll do another quick review of everything in the thread, but I think that's probably the best solution, even if it doesn't per se solve the problem in the original post. If there's no other offers, I'll be happy to write up a short summary of everything for the benefit of whoever might stumble across this thread trying to solve a similar issue.

Nel_Fie

  • New Member
  • *
  • Posts: 15
Re: TStringGrid : Conflict between "OnEditingDone" and "Columns.Clear"
« Reply #16 on: June 02, 2023, 06:17:51 pm »
So, before I forget to do it, here's a short summary of this thread, for anyone who might come across it while trying to solve a similar issue:

1) We don't really know why there is an error or how to fix it directly. The best guess as to the cause of the error is that it's caused by the program trying to retrieve data from the grid while it's being cleared - thus making the data unavailable.
Although I can't testify first hand, it's been suggested that TStringGrid might be calling "OnEditingDone" more often than necessary.

A few solutions have been suggested, but they consist mostly of a workaround, notably to delay and run part of the process in a separate thread, or something of the sort. If you want to do that, then this page of the Lazarus wiki might help: Multithreaded Application Tutorial

2) Overall, we came to the conclusion that using "TStringGrid.Clear" is probably best avoided as much as possible. So, check if it is really needed in your project, and whether or not there are alternative solutions.

I haven't fully managed to implement my own yet, but here is a rough description of what I'm doing to implement an equivalent result to what I did with "Clear":
  • Clean your grid of all data.
  • Create a template list of all column titles needed.
  • Check that the number of column matches. Delete or add as necessary.
  • Rename every column in order based on your template list of titles.
  • Repopulate your grid with data.
  • Hide every column that you want to be invisible, and show those that should be visible.

 

TinyPortal © 2005-2018