Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Sorting trouble
Wed, Apr 19 2017 7:27 AMPermanent Link

Matthew Jones

I have a TObjectList derived list that I use for sorting. I am getting odd results, with the values not ending up as expected. I can't work out why. Anyone else use TObjectList and SortCompare? Is it working okay for you?

--

Matthew Jones
Wed, Apr 19 2017 7:41 AMPermanent Link

Matthew Jones

Matthew Jones wrote:

> I have a TObjectList derived list that I use for sorting. I am getting odd results, with the values not ending up as expected. I can't work out why. Anyone else use TObjectList and SortCompare? Is it working okay for you?

Okay, sussed it. I am used to sort functions that accept a difference, and use <0, 0 or >0 as their sort values. So a simple subtraction of two values is okay. However, the EWB sort is using a fixed -1, - or +1, and indeed the CompareStr function returns one of these two values.

So in addition to my first line:

   result := xJobR.DeleteStatus - xJobL.DeleteStatus; // inverted

I need to add this for numerical results:

   if result < 0 then
       Result := CMP_LESS
   else if result > 0 then
       Result := CMP_GREATER;


--

Matthew Jones
Image