Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002992 [JEDI VCL] 00 JVCL Components minor always 2005-05-25 01:09 2005-06-14 05:25
Reporter WBenner View Status public  
Assigned To obones
Priority normal Resolution fixed  
Status resolved   Product Version 3.00
Summary 0002992: Assign in tjvSimpleXMLElem works not correct
Description The Assign-Statement of tjvSimpleXMLElem-Class makes no difference between the classes tjvSimpleXMLElem, tjvSimpleXMLComment and tjvSimpleXMLCData, alsways tjvSimpleXMLElem is assigned.
Additional Information Here 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);

Tags No tags attached.
Attached Files

- Relationships

-  Notes
obones (administrator)
2005-05-25 11:10

This definitely is NOT a good solution.
Assign should be overriden in the derived classes.
obones (administrator)
2005-05-25 11:27

Further to this, what's the whole point of your mod ?
I don't quite get it, is there a bug ?
WBenner (reporter)
2005-05-27 01:05

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!
obones (administrator)
2005-06-01 06:41

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.
obones (administrator)
2005-06-14 05:25

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

Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker