Vcl.ComCtrls.TCustomTreeView.CustomSort

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function CustomSort(SortProc: TTVCompare; Data: NativeInt; ARecurse: Boolean = True): Boolean;

C++

bool __fastcall CustomSort(Winapi::Commctrl::TTVCompare SortProc, System::NativeInt Data, bool ARecurse = true);

Properties

Type Visibility Source Unit Parent
function public
Vcl.ComCtrls.pas
Vcl.ComCtrls.hpp
Vcl.ComCtrls TCustomTreeView

Description

Sorts the nodes in the tree view into a customized sort order.

CustomSort triggers node sorting or resorting, using a comparison routine indicated by the SortProc parameter.

The Data parameter provides a way to pass information to a customized comparison routine. Data is not used by the CustomSort method or the default comparison routine.

The optional ARecurse parameter (default True) specifies that sorting should recursively descend the node tree and sort each subtree in turn.

The Return Value of CustomSort indicates the success status of the sort.

If SortProc is nil (Delphi) or NULL (C++), a default comparison routine is used. The default routine uses the OnCompare event handler, if defined. If the OnCompare event handler is not defined, the default routine uses a simple case-sensitive comparison of node captions.

The comparison routine is defined like this:

Delphi
type TTVCompare = function(lParam1, lParam2, lParamSort: Longint): Integer;
C++
typedef int (CALLBACK *PFNTVCOMPARE)(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);

The lParam1 and lParam2 parameters refer to two nodes when cast to TTreeNode.

The lParamSort parameter is the value previously passed in the Data parameter of CustomSort.

The Return Value of the comparison routine indicates the relative sort order of IParam1 and IParam2:

Return Value Meaning

< 0

IParam1 comes before IParam2.

0

IParam1 and IParam2 are equivalent.

> 0

IParam2 comes before IParam1.

Calling CustomSort has the same effect as calling the same method for the Items property, except that in TTreeNodes, CustomSort is not recursive by default.

To sort a subtree, call the CustomSort method of the Items property.

See Also

Code Examples