Forum > Packages and Libraries
TVirtualStringTree Sort Creating Duplicated Items
(1/1)
pabsungenis:
Trying to migrate an application of mine to use VirtualStringTrees because of the length of time it takes to populate nearly 2000 items into a ListView, and if I use an OwnerData ListView I can't get it to sort.
When the VST has been populated, if I scroll down to the bottom I see the first image.
After trying to sort to reverse the list, I end up with the second image.
Scrolling back, all of the other songs are duplicated over and over until I get down about 150 nodes, at which point they continue normally from that point. See the third image.
The Data record is just a pointer to an existing Object list. The CompareNodes function is here:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TMusicLibraryTreeForm.MusicLibraryTreeCompareNodes( Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);var Data: PTVTMusicRecord; So1, So2: TSong;begin Data := PTVTMusicRecord(TVirtualStringTree(Sender).GetNodeData(Node1)); So1 := TSong(Data^.Song); Data := PTVTMusicRecord(TVirtualStringTree(Sender).GetNodeData(Node2)); So2 := TSong(Data^.Song); Case Column Of 0: Result := CompareText(So1.CD,So2.CD); 1: Result := CompareChar(So1.Category,So2.Category,1); 2: Result := So1.Len - So2.Len; 3: Result := CompareText(So1.Artist,So2.Artist); 4: Result := CompareText(So1.Title,So2.Title); 5: Result := So1.Tempo - So2.Tempo; 6,7 : Result := CompareDateTime(So1.LastPlay,So2.LastPlay) end;end;
What am I doing wrong?
Pascal:
1.) How do you initialize the nodes/populate the tree? Is the data in a TList?
2.) IIRC the Result of OnCompareNode needs to be -1, 0 or 1. So So1.Len - So2.Len will not work.
pabsungenis:
Problem solved. It wasn't a bug in my coding, it was data corruption. Something fouled up the database I was loading the songs from, giving me over 51000 entries instead of 1887. Back to the backup.
Navigation
[0] Message Index