oczywiście problem opisuję tylko na jednej liście. co do posortowania to odpada bo trudno mówić o posortowaniu 4 (i tylko 4) takich_samych elementów (innymi słowy moja lista z dupIgnore zawiera stringi 'a' 'a' 'a' i...'a' !). sprawdziłem czy nie jest to (jakimś dziwnym) przypadkiem kwestia spacji których w lisbox'sie nie widzę ale to nie to.
<zmartwiony>
nauczony doświadczeniem jakoś nie chce mi się wierzyć żeby to była wina :) kogoś innego niż ja, ale tak czy siak dziwne to...postuję pełny listing odpowiedzialnego kodu:
(który jest wstępem do rozwiązania tego problemu:
http://4programmers.net/Forum/280462?h=snw#id280462
[najpierw sortuję listę wdg znaku '', a następnie dzielę na parę list, każdą jedną na 'poziom' zagłębienia folderów])
//globale:
var
FolderLevelsArr : array of TTntStringList;
SortList : TTntStringList;
FileList : pointer;
function CountCharPos(const subtext: string; Text: string): Integer;
begin
if (Length(subtext) = 0) or (Length(Text) = 0) or (Pos(subtext, Text) = 0) then
Result := 0
else
Result := (Length(Text) - Length(StringReplace(Text, subtext, '', [rfReplaceAll]))) div Length(subtext);
end;
function BackslashWideStringListCompareStrings(List: TTntStringList; Index1, Index2: Integer): Integer;
begin
Result:=(CountCharPos('\',List.Strings[Index1])-CountCharPos('\',List.Strings[Index2]));
end;
procedure SortByBackslash;
begin
SortList:=TTntStringList.Create;
SortList.Assign(TAHCustomListBox(FileList).Items);
SortList.CustomSort(BackslashWideStringListCompareStrings);
end;
//tego jeszcze w ogóle nie optymalizowałem więc jest chaos w indeksach i zmiennych iteracyjnych...
procedure TMain.Button18Click(Sender: TObject);
var i,j,k,l:integer;
begin
SortByBackslash;
i:=CountCharPos('\',SortList[0])+1;
l:=i;
k:=0;
SetLength(FolderLevelsArr, high(FolderLevelsArr)+2);
FolderLevelsArr[0]:=TTntStringList.Create;
FolderLevelsArr[0].Duplicates:=dupIgnore;
repeat
SetLength(FolderLevelsArr, high(FolderLevelsArr)+2);
FolderLevelsArr[i-l+1]:=TTntStringList.Create;
FolderLevelsArr[i-l+1].Duplicates:=dupIgnore;
repeat
FolderLevelsArr[i-l+1].Add(SortList[k]);
FolderLevelsArr[i-l].Add(ExtractFilePath(SortList[k]));
inc(k);
if k<=(SortList.Count-1) then
j:= CountCharPos('\',SortList[k])
else break;
until (i<(j+1));
inc(i);
until k>(SortList.Count-1);
TAHCustomListBox(FileList).Items.Clear;
for i:=0 to high(FolderLevelsArr) do
TAHCustomListBox(FileList).Items.AddStrings(FolderLevelsArr[i]);
TAHCustomListBox(FileList).Refresh
end;