View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002992 | JEDI VCL | 00 JVCL Components | public | 2005-05-25 01:09 | 2005-06-14 05:25 |
Reporter | WBenner | Assigned To | obones | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | 3.00 | ||||
Target Version | Fixed in Version | 3.10 | |||
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); var Elems: TJvSimpleXMLElem; Elem: TJvSimpleXMLElem; I: Integer; begin Clear; if Value = nil then Exit; 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 begin If Elems.Items[i] is tjvSimpleXMLElemComment then Elem := Items.AddComment(Elems.Items[I].Name, Elems.Items[I].Value) else If Elems.Items[i] is tjvSimpleXMLElemCData then Elem := Items.AddCData(Elems.Items[I].Name, Elems.Items[I].Value) else If Elems.Items[i] is tjvSimpleXMLElem then Elem := Items.Add(Elems.Items[I].Name, Elems.Items[I].Value); Elem.Assign(TJvSimpleXMLElem(Elems.Items[I])); end; end; | ||||
Tags | No tags attached. | ||||
|
This definitely is NOT a good solution. Assign should be overriden in the derived classes. |
|
Further to this, what's the whole point of your mod ? I don't quite get it, is there a bug ? |
|
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! |
|
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 begin Elem := TJvSimpleXMLElemClass(Elems.Items[I].ClassType).Create(Elems.Items[I].Parent); Elem.Assign(Elems.Items[I]); Items.Add(Elem); end; 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. |
|
Well, no answers in the past 14 days, the proposed code is in CVS. |
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 |