View Issue Details

IDProjectCategoryView StatusLast Update
0002992JEDI VCL00 JVCL Componentspublic2005-06-14 05:25
ReporterWBennerAssigned Toobones 
Status resolvedResolutionfixed 
Product Version3.00 
Target VersionFixed in Version3.10 
Summary0002992: Assign in tjvSimpleXMLElem works not correct
DescriptionThe Assign-Statement of tjvSimpleXMLElem-Class makes no difference between the classes tjvSimpleXMLElem, tjvSimpleXMLComment and tjvSimpleXMLCData, alsways tjvSimpleXMLElem is assigned.
Additional InformationHere is my solution for this problem:

procedure TJvSimpleXMLElem.Assign(Value: TJvSimpleXMLElem);
  Elems: TJvSimpleXMLElem;
  Elem: TJvSimpleXMLElem;
  I: Integer;
  if Value = nil then
  Elems := TJvSimpleXMLElem(Value);
  Name := Elems.Name;
  Self.Value := Elems.Value;
  for I := 0 to Elems.Properties.Count - 1 do
    Properties.Add(Elems.Properties[I].Name, Elems.Properties[I].Value);

  for I := 0 to Elems.Items.Count - 1 do
    If Elems.Items[i] is tjvSimpleXMLElemComment then
      Elem := Items.AddComment(Elems.Items[I].Name, Elems.Items[I].Value)
    If Elems.Items[i] is tjvSimpleXMLElemCData then
      Elem := Items.AddCData(Elems.Items[I].Name, Elems.Items[I].Value)
    If Elems.Items[i] is tjvSimpleXMLElem then
      Elem := Items.Add(Elems.Items[I].Name, Elems.Items[I].Value);

TagsNo tags attached.



2005-05-25 11:10

administrator   ~0007344

This definitely is NOT a good solution.
Assign should be overriden in the derived classes.


2005-05-25 11:27

administrator   ~0007347

Further to this, what's the whole point of your mod ?
I don't quite get it, is there a bug ?


2005-05-27 01:05

reporter   ~0007362

This IS a good solution because it works and because it is necessary. The original code had a bug. If a tjvsimpleXMLElem object contains some members of different classes how tjvsimpleXMLComment and tjvsimpleXMLCData and you want assign this to a new object then ALL members will assigned as tjvsimpleXMLElem!


2005-06-01 06:41

administrator   ~0007378

Ok, I agree on the "bug", but NO your solution is NOT a good solution as it does not allow for easy extension. As a principle, a base class should NEVER know a single thing about its derived classes.
There is however a solution to this problem, where you replace the existing loop with this one:

  for I := 0 to Elems.Items.Count - 1 do
    Elem := TJvSimpleXMLElemClass(Elems.Items[I].ClassType).Create(Elems.Items[I].Parent);

With TJvSimpleXMLElemClass declared as "class of TJvSimpleXMLElem".
This way, the virtual constructor of the derived class is always called, and the parent does not have to know about it.
I've tried here, it works, but please tell us if it works as well on your end. Only then this will go in CVS.


2005-06-14 05:25

administrator   ~0007458

Well, no answers in the past 14 days, the proposed code is in CVS.

Issue History

Date Modified Username Field Change
2005-05-25 01:09 WBenner New Issue
2005-05-25 11:10 obones Note Added: 0007344
2005-05-25 11:27 obones Note Added: 0007347
2005-05-27 01:05 WBenner Note Added: 0007362
2005-06-01 06:41 obones Note Added: 0007378
2005-06-01 06:41 obones Status new => feedback
2005-06-14 05:25 obones Status feedback => resolved
2005-06-14 05:25 obones Resolution open => fixed
2005-06-14 05:25 obones Assigned To => obones
2005-06-14 05:25 obones Note Added: 0007458