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.

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

Related posts
AndroidC++BuilderCode SnippetDelphiDemoFiremonkeyIOSOSXShowcaseWindows

Powerful Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

Significant Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

C++BuilderDelphiIDEWindows

Professional SVG Icon Image List For Delphi 10.4 FireMonkey On Windows

AndroidC++BuilderDelphiFiremonkeyIOSLiveBindingsOSXWindows

Top Tips And Tricks To Speed Up Development With Delphi 10.4 FireMonkey On Android and IOS

Sign up for our Newsletter and
stay informed

Leave a Reply