[Overview][Types][Classes][Procedures and functions][Index] |
Event handler signalled to compare file items in a custom sort routine.
Source position: shellctrls.pas line 144
public property TCustomShellTreeView.OnSortCompare : TFileItemCompareEvent |
OnSortCompare is a TFileItemCompareEvent property with the event handler signalled to implement a custom file sort for the tree view control. OnSortCompare is used to order the directories or files displayed in the tree view control when the FileSortType property is set to fstCustom.
Changing the routine assigned to the property causes the Items in the control to be reloaded and ordered at run-time starting at the top-level tree node in Root. The Path property is used to to expand and select a tree node after the sort operation has been completed if the path still exists and is valid for the settings in ObjectTypes.
An application can implement and assign a routine using the signature perform custom file comparison routines using various attributes. The following is an item compare function, as implemented by forum member d7_2_laz, used to order items with leading Underscore characters:
function TForm1.SortCompareUnderscore(Item1, Item2: TFileItem): integer; begin // Make sure that folders are moved to the top Result := ord(Item2.isFolder) - ord(Item1.isFolder); if Result = 0 then if (pos('_', Item1.FileInfo.Name) = 1) or (pos('_', Item2.FileInfo.Name) = 1) then Result := AnsiCompareText(Item1.FileInfo.Name, Item2.FileInfo.Name) else Result := CompareText(Item1.FileInfo.Name, Item2.FileInfo.Name); end;
Sort File Items by Date
function TForm1.SortCompareByDate(Item1, Item2: TFileItem): integer; begin // Folders first ... Result := ord(Item2.isFolder) - ord(Item1.isFolder); if Result = 0 then begin // then file date ... Result := CompareValue(Item1.FileInfo.TimeStamp, Item2.FileInfo.TimeStamp); if Result = 0 then // then file name Result := CompareText(Item1.FileInfo.Name, Item2.FileInfo.Name); end; end;
Sort File Items by Size
function TForm1.SortCompareBySize(Item1, Item2: TFileItem): integer; begin // Folders first Result := ord(Item2.isFolder) - ord(Item1.isFolder); if Result = 0 then begin // then file size ... Result := Item1.FileInfo.Size - Item2.FileInfo.Size; if Result = 0 then // then file name Result := CompareText(Item1.FileInfo.Name, Item2.FileInfo.Name); end; end;
Added in LCL version 3.0.
|
Indicates the sort type used for items (tree nodes) on the tree view control. |
|
|
Contains the tree nodes used to represent the hierarchical tree structure for the tree view control. |
|
|
Indicates the file system objects displayed using the control. |
|
|
Indicates the directory or path which is the top-level node in the tree view. |
|
|
Path to the directory displayed in the shell control. |
|
|
Checks whether the specified path is a valid file system object and type for the tree view control. |
|
|
Adds tree nodes for file system objects found starting at the specified node / path. |
|
|
Fills the tree view when the Root directory is empty. |
|
|
Represents sorting options for the items in a shell control. |
Version 4.0 | Generated 2025-05-03 | Home |