[Overview][Types][Classes][Procedures and functions][Index] |
Implements a handler routine used to compare values in a custom file sort for TCustomShellTreeView.
Source position: shellctrls.pas line 73
type TFileItemCompareEvent = function( |
Item1: TFileItem; |
Item2: TFileItem |
):Integer of object; |
Item1 |
|
First file item for the comparison routine. |
Item2 |
|
Second file item for the comparison routine. |
Integer with the relative sort order for the compared file items.
TFileItemCompareEvent is the type used to implement the OnSortCompare event handler in TCustomShellTreeView. TFileItemCompareEvent compares the file items specified in the Item1 and Item2 arguments to determine which value occurs first in the sort order.
The return value is an Integer with the relative sort order for the compared values:
An application can implement and assign a routine using the signature to the OnSortCompare event handler in TCustomShellTreeView. Set its FileSortType property to fstCustom to enable the handler routine.
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;
|
Event handler signalled to compare file items in a custom sort routine. |
|
|
Indicates how the items should be sorted in the tree. |
|
|
Provides information about a file or directory on the local file system for use in file sort comparison routines. |
Version 3.2 | Generated 2024-02-25 | Home |