 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Manzajur Guest
|
Posted: Wed Dec 27, 2006 3:15 pm Post subject: My personal solution for boolean type |
|
|
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!  |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Dec 28, 2006 2:00 am Post subject: Re: My personal solution for boolean type |
|
|
"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
|
Posted: Fri Jan 05, 2007 3:30 pm Post subject: Re: My personal solution for boolean type |
|
|
Tested and works fine.
Thanks a lot! |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Jan 06, 2007 12:35 am Post subject: Re: My personal solution for boolean type |
|
|
"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 |
|
 |
|
|
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
|
|