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.

Easily Sort String Lists And Objects With CustomSort In Delphi XE7 Firemonkey On Android And IOS by Delphi XE5 XE6 XE7 XE8 10 Seattle Berlin Firemonkey, Delphi Android, Delphi IOS is licensed under a Creative Commons Attribution 4.0 International License.

Leave a Reply

Show Buttons
Hide Buttons
Read previous post:
Delphi XE7 Firemonkey Mask Edit
Create A Custom Mask Edit Validation Event In Delphi XE7 Firemonkey On Android And IOS

If you are doing any kind of validation of fields with a TEdit component in Delphi XE7 Firemonkey you may...

Close