[Overview][Types][Classes][Procedures and functions][Index] |
Event handler signalled to compare file items in a custom sort routine.
Source position: shellctrls.pas line 143
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 its FileSortType property is set to fstCustom.
Changing the routine assigned to the property causes the Items in the control to be reloaded and ordered using the new file sort compare routine. The Path property is used to to expand and select a node 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 in the tree. |
|
|
The container with the TTreeNode instances for the control. |
|
|
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. |
|
|
Indicates the file system objects displayed using the 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. |
|
|
Indicates the directory to start showing the list of items. |