BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

My personal solution for boolean type

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML
View previous topic :: View next topic  
Author Message
Manzajur
Guest





PostPosted: Wed Dec 27, 2006 3:15 pm    Post subject: My personal solution for boolean type Reply with quote



Delphi write boolean variables as 'True' and cannot validate with a XSD
because it'd be 'true' so, I have been searching for solutions, and I
want to propose the next:

Copy XMLDoc.pas file to your project and modify TXMLNode.SetNodeValue

procedure TXMLNode.SetNodeValue(const Value: OleVariant);
begin
if VarIsType(Value, varBoolean) then
begin { workaround --- delphi set boolean as (T)rue but xsd define
boolean as 'true' or 'false' and this generate no valid xml. }
SetLength(SysUtils.TrueBoolStrs, 1);
SetLength(SysUtils.FalseBoolStrs, 1);
SysUtils.TrueBoolStrs[0] := 'true';
SysUtils.FalseBoolStrs[0] := 'false';
SetText(VarToWideStr(BoolToStr(Value, True)));
end
else
SetText(VarToWideStr(Value));
end;


Any optimizations or suggestions?
Thanks!

PD: Sorry my English! Wink
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Dec 28, 2006 2:00 am    Post subject: Re: My personal solution for boolean type Reply with quote



"Manzajur" <estival (AT) ati (DOT) es> wrote in message
news:1167210905.899083.207180 (AT) 48g2000cwx (DOT) googlegroups.com...

Quote:
Delphi write boolean variables as 'True' and cannot validate with a XSD
because it'd be 'true' so, I have been searching for solutions, and I
want to propose the next:

I would not recommend that approach. There is no need to modify the
contents of the True/FalseBoolStrs array in the first place, especially
since doing so has global consequences. Also, there is no need to convert
the OleVariant to a string and then back to a Boolean. It would be much
better to handle the boolean values locally inside the procedure directly,
for example (untested):

procedure TXMLNode.SetNodeValue(const Value: OleVariant);
const
cBoolValues: array[Boolean] of DOMString = ('false', 'true'); // do
not localize
var
S: DOMString;
B: Boolean;
begin
if VarIsType(Value, [varBoolean, varBoolean or varByRef]) then
begin
B := Value;
S := cBoolValues[B];
end else
S := VarToWideStr(Value);
SetText(S);
end;


Gambit
Back to top
Manzajur
Guest





PostPosted: Fri Jan 05, 2007 3:30 pm    Post subject: Re: My personal solution for boolean type Reply with quote



Tested and works fine.

Thanks a lot!
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Jan 06, 2007 12:35 am    Post subject: Re: My personal solution for boolean type Reply with quote

"Manzajur" <estival (AT) ati (DOT) es> wrote in message
news:1167989454.740091.232100 (AT) s34g2000cwa (DOT) googlegroups.com...
Quote:
Tested and works fine.

Please report this to QC.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.