Hi,
TStringGrid sorts everything as string!
To improve that i developed TSortGrid, derived from TStringGrid, but capable of sorting Integer, Float, Date, Time, String and show up- and down- Arrows in Titlebar.
See
https://github.com/JohnML1/SortGrid.git (https://github.com/JohnML1/SortGrid.git)
... hope its useful :-)
1. Rename the lpk file to something more meaningful like laz_sortgrid.lpk instead of sortgrid1.lpkIs that needed? The package name will be shown in a list of Lazarus packages. Thus everybody knows it is for Lazarus. Besides, the suffix .lpk stands for "Lazarus PacKage" as opposed to Delphi or any other package. It is unambiguous.
IMHO better longer name, like TSortStringGrid, TSortableStringGrid, to show that its child of StringGrid...I guess the component introduces pseudo-types for the columns. The actual data are still strings which must be converted every time for comparison.
Is that needed?No, not necessarily. It was just an idea. I did not like the "1" in the package name "sortgrid1.lpk". I feel an uncontrollable urge to delete the "1" :)
I know I myself am guilty of some of these abuses.I don't think it's an abuse. Many people added the laz prefix/suffix to their package name. Indylaz, LazRichView, LazSerial, LazAutoUpdate, etc..just to mention a few. Propably to distinguish between Lazarus/Delphi packages.
And how does OPM handle the case that a package such as "laz_chemtext.lp", is renamed to "chemtext.lpk"?I have to modify the main json too. The package name and the absolute path of the package inside the zip, must stay the same. It wouldn't be to hard to make the necessary adjustments but in my opinion it's not worth the effort.
I am a bit in doubt whether a grid which just implements a sorting method is justified to occupy a place in the component palette. Just for sorting if would be enough to put the Compare routine into a separate unit which might just be called to enable this feature in any existing string grid. (I did not have a too close look at TSortGrid, though).True, but in the beginning I promised that every package will be accepted(http://forum.lazarus.freepascal.org/index.php/topic,34297.msg224412.html#msg224412), and since the install is optional it wont' interfere with the component palette(unless you install it, of course).
In the long term I'd prefer a more general extended gird, not one just for sorting, to prevent cluttering the component palette of lots of dedicated grids.
I am a bit in doubt whether a grid which just implements a sorting method is justified to occupy a place in the component palette. Just for sorting if would be enough to put the Compare routine into a separate unit which might just be called to enable this feature in any existing string grid. (I did not have a too close look at TSortGrid, though).DoCompareCells is an overridden method. It requires an inherited class.
I checked the actual code.I am a bit in doubt whether a grid which just implements a sorting method is justified to occupy a place in the component palette. Just for sorting if would be enough to put the Compare routine into a separate unit which might just be called to enable this feature in any existing string grid. (I did not have a too close look at TSortGrid, though).DoCompareCells is an overridden method. It requires an inherited class.
Otherwise the code is not very clever. It is slower than it should be. There is no handling of error situations. With mixed valid / invalid data it will give unexpected results.