lazutils: fixed TAVLTree using fnodemgr

git-svn-id: trunk@54538 -
This commit is contained in:
mattias 2017-04-06 10:08:39 +00:00
parent 7fa04aed29
commit 9424db5d62
2 changed files with 11 additions and 7 deletions

View File

@ -38,6 +38,7 @@ type
procedure FreeAndDelete(ANode: TAVLTreeNode); override;
property OwnsObjects: boolean read FOwnsObjects write FOwnsObjects;
end;
TAvgLvlTreeClass = class of TAvgLvlTree;
{ TIndexedAVLTreeNode }
@ -48,7 +49,7 @@ type
{ TIndexedAVLTree }
TIndexedAVLTree = class(TAvlTree)
TIndexedAVLTree = class(TAvgLvlTree)
private
function GetItems(Index: SizeInt): Pointer; inline;
protected

View File

@ -244,7 +244,7 @@ end;
function TAVLTree.Add(Data: Pointer): TAVLTreeNode;
begin
Result:=fNodeMgr.NewNode;
Result:=NewNode;
Result.Data:=Data;
Add(Result);
end;
@ -292,16 +292,16 @@ end;
function TAVLTree.NewNode: TAVLTreeNode;
begin
if LazNodeMemManager<>nil then
Result:=LazNodeMemManager.NewNode
if fNodeMgr<>nil then
Result:=fNodeMgr.NewNode
else
Result:=NodeClass.Create;
end;
procedure TAVLTree.DisposeNode(ANode: TAVLTreeNode);
begin
if LazNodeMemManager<>nil then
LazNodeMemManager.DisposeNode(ANode)
if fNodeMgr<>nil then
fNodeMgr.DisposeNode(ANode)
else
ANode.Free;
end;
@ -628,7 +628,7 @@ procedure TAVLTree.Clear;
if ANode.Left<>nil then DeleteNode(ANode.Left);
if ANode.Right<>nil then DeleteNode(ANode.Right);
end;
fNodeMgr.DisposeNode(ANode);
DisposeNode(ANode);
end;
// Clear
@ -1326,6 +1326,9 @@ procedure TAVLTree.SetNodeManager(NewMgr: TBaseAVLTreeNodeManager;
AutoFree: boolean);
// only allowed just after create.
begin
if fNodeMgr=NewMgr then exit;
if Count>0 then
raise Exception.Create('TAVLTree.SetNodeManager');
if fNodeMgrAutoFree then
FreeAndNil(fNodeMgr);
fNodeMgr:=NewMgr;