Delphi Pascal Source Code - Selection Sort http://www.awitness.org/delphi_pascal_tutorial/index.html Using Selection Sort to sort a Tstrings type using the 'Exchange' method... Using Selection sort to arrange the elements in an OpenDialog.Files Tstrings element... procedure TForm1.OpenDialogSortfiles; var counter, look:integer; temp:Tstrings; begin if OpenDialog1.Files.Count<>1 then begin temp := TStringList.Create; {strings with mixed upper and lower case names will not sort alphabetically since strings are sorted based on the digital value of letters and not the letters themselves...therefore the sort will be based upon lowercase strings but the filenames themselves will not be changed to avoid the possiblity of error messages on systems set to be case sensitive ... The OpenDialog Tstrings property is Read Only so in order for the sort to work correctly a temporary Tstrings variable will be used to hold the actual indexing value for the sort} for counter:=0 to OpenDialog1.Files.Count-1 do temp.Append(LowerCase(OpenDialog1.Files.Strings[counter])); for counter:=0 to temp.Count-1 do {place the smallest element in the first position, move to the second position, and place the next smallest element in the second position, etc} for look:=counter+1 to temp.Count-1 do if temp[look]