It took a week to solve a problem. At the same time, the first time I really started to use generic arrays, it felt great.
If you use tarray <word> instead of array of word, you can also useAlgorithm(Point missing ).
Uses generics. collections, generics. defaults; {sort method for testing tarray} procedure tform1.button1click (Sender: tobject); var arr: tarray <string>; // same as array of string S: string; begin setlength (ARR, 5); arr [0]: = 'aaa'; arr [1]: = 'aaa'; arr [2]: = '000000'; arr [3]: = '000000'; arr [4]: = '000000'; tarray. sort <string> (ARR); memo1.clear; for S in arr do memo1.lines. add (s); // 111 222 333 AAA aaaend; {test binarysearch method of tarray} procedure tform1.button2click (Sender: tobject); var arr: tarray <integer>; // same as array of integer I, n: integer; begin setlength (ARR, 5); for I: = 0 to length (ARR)-1 do arr [I]: = INTEGER (sqr (I); memo1.clear; for I: = low (ARR) to high (ARR) Do memo1.lines. add (inttostr (ARR [I]); If tarray. binarysearch <integer> (ARR, 4, N) Then showmessage (inttostr (n); // 2, that is, the third if tarray. binarysearch <integer> (ARR, 5, n) Then showmessage (inttostr (n); // end cannot be determined based on N when it is not found; {custom sorter} procedure tform1.button3click (Sender: tobject); var arr: tarray <integer>; num: integer; begin setlength (ARR, 5); arr [0]: = 2; arr [1]: = 4; arr [2]: = 3; arr [3]: = 1; arr [4]: = 5; tarray. sort <integer> (ARR, tcomparer <integer>. construct (function (const A, B: integer): integer begin result: = B-A; End); memo1.clear; For num in arr do memo1.lines. add (inttostr (Num); // 5 4 3 2 1end;