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 Tutorial2) 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.