2006/5/2, Marc Santhoff <[EMAIL PROTECTED]>:
It is in fact Delphi that did it that way
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.
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
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal