caymon 0 Posted October 30, 2023 I have a list of objects, declared like TMyList = class(TObjectList<T>) with say 1000 elements. The list is sorted according to a certain comparer. Then, how do I sort again, but only the first 100 elements of that list, according to another comparer. The construction MyList.Sort(...) doesn't allow to specify a low and a high bound of the sort. Share this post Link to post
Fr0sT.Brutal 900 Posted October 31, 2023 If speed is not critical, you can determine the index of each object from inside comparer callback via IndexOf Share this post Link to post
Uwe Raabe 2057 Posted October 31, 2023 You didn't mention the Delphi version, but since Delphi 11 you can use the appropriate Sort overload taking a comparer, start index and count. procedure Sort; overload; procedure Sort(const AComparer: IComparer<T>); overload; procedure Sort(const AComparer: IComparer<T>; Index, Count: Integer); overload; 2 1 Share this post Link to post
caymon 0 Posted October 31, 2023 Thank you for the info about Delphi 11. Indeed, I have that version but the program that needs the change (600K lines) was compiled using 10.4. However, I've checked that it also compiles (and seems to run) properly using 11, maybe it is time to switch! Share this post Link to post
Stefan Glienke 2002 Posted October 31, 2023 Using 10.4 you can do this with the following code: TArray.Sort<yourtype>(list.PList^, list.Comparer, index, count); 1 Share this post Link to post