I think about for certain use cases to use more the Shell Controls instead of self written stuff.
Because it's easy, slim and fast to use without much overhead. Nowadays even with builtin system icons ...
Actually i stumble across two things though. One is this small one:
Regarding folders as well as files, differently from common used file explorers / windows items beginning with underbar ("_") are sorted at the end, not at the beginning:
I noticed that because i'm using the underscore oftenly to bring some items in a certain attention:
__savedVersions
_tempStuff
Work1
I'd suggest that the comps follow the established sorting rules, eg. shown by Windows explorer, or others.
On the other hand:
for the shell listview i assume that using the OnCompare callback resp. some customsort rules possibly could customize that on app level-
But: the shell treeview does not expose such an OnCompare, right??
It seems to use "
CompareText" and this returns:
CompareText ('a', 'b') -1 (negative value) 'a' is smaller thand 'b'
CompareText ('_', 'b') 30 (positive value) '_' is greater than 'a'
Rrenark:
AnsiCompareText instead would deliver the desired result. I don't know if it can ssen as a good solution. but at least it does met the expectation (i tried it with the ShellViewEx demo that was contributed times ago within the forum (fantasic demo!). That uses self-coded "GetFiles" (virtual paradigm, OwnerData) for to gain speed. And it exposes a sort routine that i could adapt and test.
However, AnsiCompareText seems to slowdown the process here, as i could see (nearly doubled speed loss) . A conditional usage of this function does solve that effect sufficiently.
function Compare(Item1, Item2: Pointer): Integer;
var FileData1: PFileData; FileData2: PFileData; S1, S2: String;
begin
FileData1 := PFileData(Item1);
FileData2 := PFileData(Item2);
if (FileData1^.FIsDir = FileData2^.FIsDir) then begin
S1 := FileData1^.FName;
S2 := FileData2^.FName;
if ((Pos('_', S1) > 0) Or (Pos('_', S2) > 0)) then
Compare := AnsiCompareText(S1, S2)
else
Compare := CompareText(S1, S2);
end
else
Compare := Ord(FileData2^.FIsDir) - Ord(FileData1^.FIsDir)
end;
But how to apply that sort override to the shell treeview?