mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 18:36:10 +02:00
avglvltree: setcompare: set when count=0
git-svn-id: trunk@38486 -
This commit is contained in:
parent
75c516c1ea
commit
30aefa3503
@ -1577,30 +1577,33 @@ var List: PPointer;
|
||||
i, OldCount: integer;
|
||||
begin
|
||||
if (FOnCompare=NewCompare) and (FOnObjectCompare=NewObjectCompare) then exit;
|
||||
if Count<1 then begin
|
||||
FOnCompare:=NewCompare;
|
||||
FOnObjectCompare:=NewObjectCompare;
|
||||
exit;
|
||||
end;
|
||||
// sort the tree again
|
||||
if Count>0 then begin
|
||||
OldCount:=Count;
|
||||
GetMem(List,SizeOf(Pointer)*OldCount);
|
||||
try
|
||||
// save the data in a list
|
||||
ANode:=FindLowest;
|
||||
i:=0;
|
||||
while ANode<>nil do begin
|
||||
List[i]:=ANode.Data;
|
||||
inc(i);
|
||||
ANode:=ANode.Successor;
|
||||
end;
|
||||
// clear the tree
|
||||
Clear;
|
||||
// set the new compare function
|
||||
FOnCompare:=NewCompare;
|
||||
FOnObjectCompare:=NewObjectCompare;
|
||||
// re-add all nodes
|
||||
for i:=0 to OldCount-1 do
|
||||
Add(List[i]);
|
||||
finally
|
||||
FreeMem(List);
|
||||
OldCount:=Count;
|
||||
GetMem(List,SizeOf(Pointer)*OldCount);
|
||||
try
|
||||
// save the data in a list
|
||||
ANode:=FindLowest;
|
||||
i:=0;
|
||||
while ANode<>nil do begin
|
||||
List[i]:=ANode.Data;
|
||||
inc(i);
|
||||
ANode:=ANode.Successor;
|
||||
end;
|
||||
// clear the tree
|
||||
Clear;
|
||||
// set the new compare function
|
||||
FOnCompare:=NewCompare;
|
||||
FOnObjectCompare:=NewObjectCompare;
|
||||
// re-add all nodes
|
||||
for i:=0 to OldCount-1 do
|
||||
Add(List[i]);
|
||||
finally
|
||||
FreeMem(List);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user