View Issue Details

IDProjectCategoryView StatusLast Update
0006062JEDI Code LibraryJclSimpleXmlpublic2013-06-16 23:03
ReporterwestphalAssigned Tojfudickar 
PrioritynormalSeveritymajorReproducibilityalways
Status feedbackResolutionopen 
Product VersionVersion 2.5 (Subversion repository/Daily zips) 
Target VersionFixed in Version 
Summary0006062: TJclSimpleXMLElems.delete leave ghost item
Descriptionusing Node.Items.ItemNamed['item1'] to create an element (with option sxoAutoCreate) return wrong element if it was deleted before.

see exemple in additional Information
Additional Informationvar
  xml : TJclSimpleXML;
  pa,Node : TJclSimpleXMLElem;
begin
  xml := TJclSimpleXML.Create;
  try
    pa := xml.Root;
    pa.Name := 'conf';
    Xml.Options := Xml.Options + [sxoAutoCreate];

    node := pa.Items.Add('item1');
    pa.Items.Add('item2');

    //pa.items.Notify(node, opRemove);
    pa.items.Delete('item1');
    node := xml.Root;
    Node.Items.ItemNamed['item1'];

    memo1.text := xml.SaveToString;
    memo1.lines.Add('pa.Items.ItemNamed[''item2''].Name = '+ pa.Items.ItemNamed['item2'].Name +' ???' );

  finally
    xml.Free;
  end;
end;
TagsNo tags attached.
Fixed in GIT commit
Fixed in SVN revision
IDE versionAll

Activities

westphal

2013-01-15 12:17

reporter   ~0020331

This is a problem when using 2 MRU components and a appXMLstorage, as they use this way to update the xml file.

westphal

2013-01-15 13:47

reporter   ~0020333

in the exemple,
a/ item1 as index 0 and item2 as index 1
b/ item1 is deleted, then item2 as index 0
c/ item1 is re-created then now item 1 as index 1

the FElems: TJclSimpleItemHashedList; is updated for item1 (FNameHash.Remove) but not for the new index of item2 !

a working correction would be:

procedure TJclSimpleItemHashedList.Notify(Ptr: Pointer; Action: TListNotification);
begin
  if (Action = lnDeleted) and (FNameHash <> nil) then
  begin
    InvalidateHash;
    {
    if FCaseSensitive then
      FNameHash.Remove(TJclSimpleItem(Ptr).Name)
    else
      FNameHash.Remove(UpperCase(TJclSimpleItem(Ptr).Name));
      }
  end;
  inherited Notify(Ptr, Action);
end;

jfudickar

2013-06-16 23:03

developer   ~0020532

Commited to github

Issue History

Date Modified Username Field Change
2013-01-15 12:16 westphal New Issue
2013-01-15 12:16 westphal IDE version => All
2013-01-15 12:17 westphal Note Added: 0020331
2013-01-15 13:47 westphal Note Added: 0020333
2013-06-16 23:03 jfudickar Note Added: 0020532
2013-06-16 23:03 jfudickar Assigned To => jfudickar
2013-06-16 23:03 jfudickar Status new => feedback