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
0002368 [JEDI VCL] 00 JVCL Components minor always 2004-12-08 17:14 2004-12-11 03:10
Reporter anonymous View Status public  
Assigned To
Priority normal Resolution fixed  
Status resolved   Product Version 3.00 BETA 2
Summary 0002368: TJvSimpleXML - reading properties with "default value" when using "sxoAutoCreate"
Description When
a) reading property element: TJvSimpleXMLProps.value(X,Y)
b) property X does not exists
c) supplies a default value Y (not an empty string)
d) sxoAutoCreate is a member of TjvSimpleXML.options.

The result of TJvSimpleXMLProps.value(X,Y) will not be the value Y, but rather an empty string.
Additional Information This code illustrates the problem;

procedure TForm1.Button1Click(Sender: TObject);
var xml :TjvSimpleXML;
    a :string;
begin
  xml:=TjvSimpleXML.create(application);
  xml.Options:=[sxoAutoCreate];
  a:=xml.Root.Properties.Value('TEST','DEFAULT');
  if a='DEFAULT' then
    showmessage('I''m default')
  else if a='' then
    showmessage('Oops, autocreated empty property');
end;

Running the example, 'a' will contain an empty string, not the value 'DEFAULT' as I would expect.
The problem lies in method TJvSimpleXMLProps.GetItemNamed which automaticly create the property with empty string. It looks like it would be safe to return nil instead of creating within TJvSimpleXMLProps.GetItemNamed.

Tags No tags attached.
Attached Files zip file icon JvSimpleXml041210.zip [^] (14,867 bytes) 2004-12-10 05:15

- Relationships

-  Notes
(0005847)
user72
2004-12-09 12:22

Try the attached update.
(0005849)
anonymous (viewer)
2004-12-09 15:08

Thanks Peter, attached file solved the problem.
(0005850)
mliesen (reporter)
2004-12-09 19:05
edited on: 2004-12-09 19:06

I just noticed that the TJvSimpleXMLElems.Value(x,y) has the same problem (using the JvSimpleXml041209.zip)

New example code:

procedure TForm1.Button1Click(Sender: TObject);
var xml :TjvSimpleXML;
  a :string;
begin
  xml:=TjvSimpleXML.create(application);
  xml.Options:=[sxoAutoCreate];
  a:=xml.Root.Items.Value('TEST','DEFAULT');
  if a='DEFAULT' then
    showmessage('I''m default')
  else if a='' then
    showmessage('Oops, autocreated empty value');
end;

(0005851)
user72
2004-12-10 05:15

Try the new file attached
(0005859)
mliesen (reporter)
2004-12-10 16:50

Almost there, line 121 and 1854;

function GetItemNamedDefault(const Name): TJvSimpleXMLProp;
should be
function GetItemNamedDefault(const Name, Default: string): TJvSimpleXMLProp;

With the above change, it works like charm. Thanks!
(0005860)
user72
2004-12-11 03:10

Updated in CVS

- Issue History
Date Modified Username Field Change
2004-12-08 17:14 anonymous New Issue
2004-12-09 12:22 user72 File Added: JvSimpleXml041209.zip
2004-12-09 12:22 user72 Note Added: 0005847
2004-12-09 12:22 user72 Status new => feedback
2004-12-09 15:08 anonymous Note Added: 0005849
2004-12-09 19:05 mliesen Note Added: 0005850
2004-12-09 19:06 mliesen Note Edited: 0005850
2004-12-10 05:14 user72 File Deleted: JvSimpleXml041209.zip
2004-12-10 05:15 user72 File Added: JvSimpleXml041210.zip
2004-12-10 05:15 user72 Note Added: 0005851
2004-12-10 16:50 mliesen Note Added: 0005859
2004-12-11 03:10 user72 Status feedback => resolved
2004-12-11 03:10 user72 Resolution open => fixed
2004-12-11 03:10 user72 Assigned To => user72
2004-12-11 03:10 user72 Note Added: 0005860
2004-12-11 03:10 user72 Assigned To user72 =>


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