[fpc-pascal] sort procedure of T(FP)List

Geno Roupsky groupsky at gmail.com
Fri May 5 10:03:34 CEST 2006


2006/5/2, Marc Santhoff <M.Santhoff at t-online.de>:
>
> Hi,
>
> i wonder why the declaration of the comparing function of list objects
> is the way it is:
>
> TListSortCompare = function (Item1, Item2: Pointer): Integer;
>
> Since I am writing a class that sorts a list it owns depending on
> another property naming the property of the list items for sorting, I
> would like to have it made a "procedure of object":
>
> TListSortCompare = function (Item1, Item2: Pointer): Integer of object;
>
> I'm dealing with lists of files and directories that should get sorted
> by name, date, ...
> If the comparing function is a plain non object function I have to make
> some sort of unit global variable or the like for telling it, what
> property is the sort criteria. I don't like this design, although in
> this case there is only one soritng process at a time.
>
> Is this a concession imposed by Delphi compatibility?


It is in fact Delphi that did it that way

(If you can suggest a better strategy for using this stuff, please do.)


In fact you could have different function for every kind of sort and switch
them on the fly when the properties determining the kind of sort that should
be made changes. In my experience there is no much code duplication involved
in this technique and you could make for example one compare function for
every field, after that you make a _complex_ ones calling the simple ones.

Either way it is not very OO based approach but of course you could make a
descendand class of tfplist and add you own sorting code.
--
Geno Roupsky
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20060505/90770cc5/attachment.html>


More information about the fpc-pascal mailing list