In Delphi / Pascal I would like to sort a TStringList alphabetically. But for this purpose, I can only use the following two methods:
Move: Moves a string from one index position to another, shifting other strings around as appropriate.
Exchange: Swaps two strings in the list, as identified by their index positions.
How could I do this? I had the idea to go through all items with a loop and to something like this:
- lastFirstLetter := Copy(CurrentItem, 1, 1)
- go to next item
- currentFirstLetter := Copy(CurrentItem, 1, 1)
- if ord(currentFirstLetter) < ord(lastFirstLetter) then exchange(lastItem, currentItem)
What would be the fastest way to sort a StringList with these two methods? I can't use the sort method and the sorted property by the way.