lazutils: TStringToPointerTree: fixed freeing value on replace

git-svn-id: trunk@53305 -
This commit is contained in:
mattias 2016-11-07 11:29:29 +00:00
parent 7d3b4320c2
commit f96014d35b

View File

@ -526,16 +526,20 @@ end;
procedure TStringToPointerTree.SetValues(const s: string; const AValue: Pointer);
var
Node: TAvgLvlTreeNode;
NewItem: PStringToPointerItem;
Item: PStringToPointerItem;
begin
Node:=FindNode(s);
if Node<>nil then begin
PStringToPointerItem(Node.Data)^.Value:=AValue;
Item:=PStringToPointerItem(Node.Data);
if Item^.Value=AValue then exit;
if FreeValues then
TObject(Item^.Value).Free;
Item^.Value:=AValue;
end else begin
New(NewItem);
NewItem^.Name:=s;
NewItem^.Value:=AValue;
FTree.Add(NewItem);
New(Item);
Item^.Name:=s;
Item^.Value:=AValue;
FTree.Add(Item);
end;
end;