Why isn't my TStringList sorted?
I have a custom sorted TStringList
...
Items.CustomSort(@CompareWords);
... with this comparison function:
function CompareWords(List: TStringList; Index1, Index2: Integer): Integer;
begin
Result := StrIComp(PWideChar(List[Index1]), PWideChar(List[Index2]));
end;
But after noticing some problems with my code that expects the list to be sorted in order StrIComp
, I created this little check ...
for i := 1 to Items.Count - 1 do
begin
Assert(StrIComp(PWideChar(Items[i-1]), PWideChar(Items[i])) <= 0);
end;
... and it doesn't work.
Why isn't the list sorted correctly?
+2
source to share