Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiDemoFiremonkeyIOSOSXWindows

Easily Sort String Lists And Objects With CustomSort In Delphi XE7 Firemonkey On Android And IOS

Delphi XE7 Firemonkey Custom Sort String Object ListIt is simple to sort a list of strings or objects in Object Pascal using TStringList from Delphi XE7 Firemonkey. TStringList provides a CustomSort function which you pass a function to that handles the sorting. The function that you pass to CustomSort should have three parameters and look like this StringListCompareStrings(List: TStringList; Index1, Index2: Integer): Integer;. The Index1 and Index2 parameters are the row IDs from the TStringList. You can do whatever you want with the row IDs. For example, you can just use the row data directly or you could access an object attached to that row and pull a specific piece of data off the object for sorting. This custom sorting function works on Android, IOS, OSX, and Windows. It should also compile under Appmethod. Here is a code snippet which demonstrates the CustomSort functionality to sort the rows as integers:

Download the demo source code for creating a custom sort function for TStringList in Delphi XE7 Firemonkey.

close

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

DelphiIDEShowcaseWindows

Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores

DelphiFiremonkeyIDEIOSOSXWindows

DelphiCon 2020 FireMonkey Sessions Available Starting November 19

AndroidC++BuilderDelphiDemoFiremonkeyWindows

Powerful Commercial Gorilla3D Framework Upgraded For Delphi FireMonkey On Windows And Android

Sign up for our Newsletter and
stay informed

Leave a Reply