title: How can I sort a TList in Delphi on an arbitrary property of the objects it contains?
body: <p>I have a TList.  It contains a collection of objects of the same type.  These objects are descended from a TPersistent, and have about 50 different published properties.  </p>
  
  <p>In my application, the user can issue a search of these objects, and the results of the search are displayed in a TDrawGrid, with the specific columns displayed being based on the properties being searched.  For example, if the user searches on 'invoice', an 'invoice' column is displayed in the results' grid.  I would like to be able to let the user sort this grid.  The kicker, of course, is that I wont know up front what columns are in the grid.</p>
  
  <p>Normally to sort a TList, I'd just make a function, such as <code>SortOnName( p1, p2)</code>, and call the TList's <code>sort()</code> method.  I'd like to go one step further and find a way to pass a property name to the sort method and use RTTI to make the comparison.    </p>
  
  <p>I could, of course, make 50 different sort methods and just use that.  Or, set a variable globally or as part of the class doing all this work to indicate to the sorting method what to sort on.  But I was curious if any of the Delphi pro's out there had other ideas on how to implement this.</p>