The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



SortRows


Unit:SDL_datatable
Class: TDataTable
Declaration: procedure SortRows (SortColIx: integer; Ascending: boolean; LowCol, LowRow, HighCol, HighRow: integer; IncludeHeaders: boolean);

The method SortRows provides a means to sort the rows of the data table, or part of it, according to the values in a single column. This column is indexed by the parameter SortColIx. The data table is sorted row by row within the range [LowCol, LowRow ] to [HighCol, HighRow ]. The values outside this range are not affected (except for the column addressed by SortColIx ). The sorting order is determined by the column SortColIdx which is also sorted within the range [LowRow, HighRow ]. The parameter Ascending specifies whether the valus are to be sorted in ascending (TRUE) or descending (FALSE) order. The parameter IncludeHeaders determines whether the row names and the columns attributes are sorted too. Note that in most cases this parameter should be set TRUE.

MATRSORT.gif

The sorting is performed by a modified bubble sort (CombSort), which has been reported to be comparable in speed to QuickSort (see also R.Box, S. Lacey, BYTE magazine, April 1991). The event OnSortExchange is triggered whenever two rows have to be exchanged during the sorting process.

Hint 1: The values of the column SortColIx are always sorted, even if this column is outside the specified sort range [LowCol, HighCol].

Hint 2: Setting both the low and high parameter of a dimension (i.e. LowCol and HighCol) to zero values forces the method to use all elements of that dimension.

Hint 3: If the sorting criterion is an ordinal or nominal variable the ordinal numbers of the data are used for the sorting process.

Example: The statement MyDTable.SortRows (10, true, 1, 1, MyDTable.NrOfColumns, MyDTable.NrOfRows, true) sorts the whole table MyDTable according to the values in column 10.


Last Update: 2023-Dec-14