I have used the code by
Ericktux from this post:
https://forum.lazarus.freepascal.org/index.php/topic,20142.msg207605.htmland it works wonderful!
There are some things that I'm not sure how to deal with. My case is when a dataset can be initially sorted by using SQL SELECT with ORDER BY statement; and ordering key may be set by application user.
I would like to show the appropriate arrow in the appropriate column title of the DBGrid after opening SQLQuery. I can do this manually, knowing the "ORDER BY" key. But maybe it is easy to discover this automatically? Or maybe it is better not to use "ORDER BY" at all and set SQLQuery indexes instead?
In my application SQLQuery can be opened again and again with modified SQL texts. If previously DBGrid was sorted with mentioned procedure, then the SQLQuery index is kept for next SQL request, and it overrides the "ORDER BY". What is the correct way to drop the previously set index of SQLQuery?
I didn't find much information about using TSQLQuery.IndexDefs...