TValueListEditor: inherited public method SortColRow not working
Original Reporter info from Mantis: wp @wpam
-
Reporter name:
Original Reporter info from Mantis: wp @wpam
- Reporter name:
Description:
Sorting of rows in a TValueListEditor presumably is supposed to be done by calling the method Sort of its Strings. However, TValueListEditor, inherits also the public method SortColRow from its ancestors. As demonstrated in the attached project, this method has no effect (I've also seen cases when it crashes the application).
Debugging the issue I found that TValueListEditor.SortByColRow calls TCustomDrawGrid.SortByColRow which in turn calls the virtual method TCustomGrid.Sort. The problem is in the call to DoExchangeColRow which is not implemented by TValueListEditor for its dedicated strings storage. In fact, this method not even is virtual.
There are two ways to fix the issue:
(1) Override the method Sort by the TValueListEditor by calling its special CustomSort which correctly handles its strings. - This is provided in the attached patch.
(2) Replace the DoExchangeColRow in TCustomGrid.Sort by ExchangeColRow (which just calls DoExchangeColRow). Make TCustomGrid.ExchangeColRow virtual. Override it in TValueListEditor such that it exchanges the two strings.
Steps to reproduce:
Run attached demo. There is a TValueListEditor at the left and a TStringGrid at the right. Both are populated by the same dummy strings. Click on the button "Sort" to sort by the 1st column (using SortColRow): Nothing happens for the TValueListEditor while the TStringGrid is correctly sorted.
Additional information:
See also forum discussion https://forum.lazarus.freepascal.org/index.php/topic,42249.msg294625.html
Mantis conversion info:
- Mantis ID: 34141
- Fixed in version: 1.10
- Fixed in revision: r58773 (#828f4e74)
- Target version: 1.10