Problem Source: http://www.cnblogs.com/del/archive/2008/04/07/1134178.html#1141173
Unit unit1; interfaceuses windows, messages, extensions, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} {write a function in descending order of numbers} function desccompareint (list: tstringlist; I1, I2: integer): integer; begin I1: = strtointdef (list [I1], 0); I2: = strtointdef (list [I2], 0); Result: = I2-I1; end; Procedure tform1.button1click (Sender: tobject); var list: tstringlist; begin list: = tstringlist. create; List. commatext: = '5, '; List. customsort (desccompareint); {the function called during sorting} showmessage (list. text); {87 65 21 5 4 3 1} List. free; end.
In addition, you can use the names and valuefromindex attributes of tstringlist to Solve the Problem corresponding to other data, or use the case statement for extraction.