[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | Reference for unit 'Grids' (#lcl)

# TCustomStringGrid.DoCompareCells

Performs a comparison between the specified cells in the grid control.

## Declaration

Source position: grids.pas line 1774

`protected function TCustomStringGrid.DoCompareCells(`
`Acol: Integer;`
`ARow: Integer;`
`Bcol: Integer;`
`BRow: Integer`
`):Integer; override;`

## Arguments

`Acol` |  | Column number for the first cell value in the comparison.
`ARow` |  | Row number for the first cell value in the comparison.
`Bcol` |  | Column number for the second cell value in the comparison.
`BRow` |  | Row number for the second cell value in the comparison.

## Function result

Relative sort order for the compared cell values.

## Description

DoCompareCells is an overridden method used to compare cell values in the Sort method. It calls the inherited method when the OnCompareCells event handler has been assigned. The return value from the event handler contains the relative sort order for the compared cells, and uses the following values:

-1
  The cell at ACol and ARow occurs comes before the cell at BCol and BRow.
0
  The specified cells have the same value.
1
  The cell at ACol and ARow occurs comes after the cell at BCol and BRow.

When OnCompareCells is not assigned, the AnsiCompareText routine is called to perform the cell comparison and provide the return value for the method. When SortOrder is set to soDescending, the return value is negated.

## See also

TCustomGrid.DoCompareCells |  | Performs a comparison between the specified cells in the grid control.
TCustomGrid.OnCompareCells |  | Event handler signalled to compare the content in grid cells.
AnsiCompareText