Skip to main content

TcxCustomDataController.DefaultCompare(Integer,Integer,Integer) Method

Executes the default comparison routine for two specified values in a dataset field.

Declaration

function DefaultCompare(ARecordIndex1: Integer; ARecordIndex2: Integer; AItemIndex: Integer): Integer;

Parameters

Name Type Description
ARecordIndex1 Integer

Specifies the index of the record that contains the first compared value.

The AItemIndex parameter specifies the index of the source dataset field.

ARecordIndex2 Integer

Specifies the index of the record that contains the second compared value.

The AItemIndex parameter specifies the index of the source dataset field.

AItemIndex Integer

Specifies the index of the source dataset field where both compared values are stored.

ARecordIndex1 and ARecordIndex2 parameters specify the record indexes of first and second compared values in the source dataset field.

Returns

Type Description
Integer

The comparison result. Refer to the following section for details: Returned Values.

Remarks

Call the DefaultCompare function within an OnCompare event handler if you need to use the default comparison algorithm instead of a custom sorting algorithm under specific conditions.

Important

If your custom sorting algorithm is not thread-safe, make sure that multi-threaded calculations are disabled for data sort operations in the data controller.

To disable multi-threading for sort operations in the data controller, set the MultiThreadedOptions.Sorting property to bFalse.

Returned Values

Returned Value Description
-1 ARecordIndex1 is positioned before ARecordIndex2.
0 ARecordIndex1 and ARecordIndex2 are considered equal. Both values retain their positions.
1 ARecordIndex1 is positioned after ARecordIndex2.

Code Example

The code example below demonstrates an OnCompare event handler that groups records with the same month in the Sale Date column when records are sorted against this column. The event handler calls the DefaultCompare function to execute the default comparison routine in all other cases.

procedure TForm1.MyOnCompareEventHandler(ADataController: TcxCustomDataController;
ARecordIndex1, ARecordIndex2, AItemIndex: Integer; const V1, V2: Variant; var Compare: Integer);
var
  AYear, AMonth1, AMonth2, ADay: Word;
begin
  // Applies custom sorting when records are sorted against the "Sale Date" column
  if (AItemIndex = DBTableView1SaleDate.Index) and
    (VarType(V1) = VarType(V2)) and (VarType(V1) = varDate) then
  begin
    DecodeDate(V1, AYear, AMonth1, ADay);
    DecodeDate(V2, AYear, AMonth2, ADay);
    // Groups records with the same month
    Compare := AMonth1 - AMonth2;
  end
  else  // Uses the default comparison algorithm in all other cases
    Compare := ADataController.DefaultCompare(ARecordIndex1, ARecordIndex2, AItemIndex);
end;
See Also