DECLARE FUNCTION SortColGrid (Sender AS QSTRINGGRID, Col% AS INTEGER, Ascend% AS INTEGER) AS STRING
FUNCTION SortColGrid
$ESCAPECHARS ON
DIM RecordsCount AS INTEGER
RecordsCount = Sender.RowCount - 1
DIM SortingArray(1 TO RecordsCount) AS STRING
DIM MemoryStream AS QMEMORYSTREAM
DIM I AS INTEGER, J AS INTEGER
IF Col% > 1 THEN Sender.SwapCols (1, Col%)
Sender.SaveToStream (MemoryStream, 1,1,RecordsCount)
MemoryStream.Position = 0
FOR J = 1 TO RecordsCount
SortingArray(J) = MemoryStream.ReadLine & "\n"
NEXT J
MemoryStream.CLOSE
IF Ascend% = 1 THEN
QUICKSORT(SortingArray(1), SortingArray(RecordsCount), Ascend)
ELSEIF Ascend% = 0 THEN
QUICKSORT(SortingArray(1), SortingArray(RecordsCount), Descend)
END IF
FOR J = 1 TO RecordsCount
MemoryStream.WriteStr(SortingArray(J), LEN(SortingArray(J)))
NEXT J
MemoryStream.Position = 0
Sender.LoadFromStream(MemoryStream, 1, 1, RecordsCount)
MemoryStream.CLOSE
IF Col% > 1 THEN Sender.SwapCols (1, Col%)
$ESCAPECHARS OFF
END FUNCTION
|