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:
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?