<div dir="ltr">I usually use integer cast to boolean values, sample:<div><br></div><div><div>var</div><div> cond: boolean;</div><div> i: integer;</div><div>begin</div><div> cond := true;</div><div><br></div><div> writeln(inttostr(integer(cond)));</div><div><br></div><div> i := 0;</div><div><br></div><div> if boolean(i) then</div><div> writeln('true')</div><div> else</div><div> writeln('false'); <br>end;</div><div><br></div><div>best regards</div><br><br></div></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr"><div style="font-size:small;font-family:arial"><br>José Benedito</div><div style="font-size:small;font-family:arial">JBS Soluções<br>Consulting Systems Development<br><a href="mailto:josebenedito@gmail.com" style="color:rgb(17,85,204)" target="_blank">c</a><a href="mailto:ontato@jbsolucoes.net" style="color:rgb(17,85,204)" target="_blank">ontato@jbsolucoes.net</a><br><div><div><a href="http://www.jbsolucoes.net/" style="color:rgb(17,85,204)" target="_blank">www.jbsolucoes.net</a></div><div><br>skype: <a href="mailto:sac@jbsolucoes.net" style="color:rgb(17,85,204)" target="_blank">sac@jbsolucoes.net</a></div></div><div>+55 22 30251654</div><div>+55 22 996064279</div></div></div></div>
<br><div class="gmail_quote">On Tue, Oct 7, 2014 at 3:46 PM, silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span class=""><div class="gmail_quote">On Sat, Oct 4, 2014 at 6:28 AM, Reinier Olislagers <span dir="ltr"><<a href="mailto:reinierolislagers@gmail.com" target="_blank">reinierolislagers@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>On 03/10/2014 21:16, silvioprog wrote:<br>
> When I use the TIniFile to save my configurations, it saves the boolean<br>
> values as 0 and 1.<br>
><br>
> Is there any way to save these values as string (true/false) instead<br>
> of integer (0/1)? If not, can I send a patch to implement that?!<br>
<br>
</span>1. Write your own wrapper?<br>
2. AFAIR, there already is a bug report+patch in the bug tracker on<br>
extending TInifiles.</blockquote></div><div><br></div></span><div>Thanks.</div><div><br></div><div>Internally it uses this functions:</div><div><br></div><div>...</div><div><div>function CharToBool(AChar: char): boolean;</div><div>begin</div><div> Result := (Achar = '1');</div><div>end;</div><div><br></div><div>function BoolToChar(ABool: boolean): char;</div><div>begin</div><div> if ABool then</div><div> Result := '1'</div><div> else</div><div> Result := '0';</div><div>end;</div></div><div>...</div><div><br></div><div>This functions could be replaced by functions from SysUtils functions, allowing compatibility with words like 0/1 (as is now), true/false, yes/no (USA), sim/não (Brazil), foo/bar (any) etc. Then:<br></div><div><br></div><div>Instead of:</div><div><br></div><div><div>function TCustomIniFile.ReadBool(const Section, Ident: string; Default: Boolean): Boolean;</div><div>var</div><div> s: string;</div><div>begin</div><div> Result := Default;</div><div> s := ReadString(Section, Ident, '');</div><div> if s > '' then</div><div> Result := CharToBool(s[1]);</div><div>end;</div></div><div><br></div><div>Could be:</div><div><br></div><div><div>function TCustomIniFile.ReadBool(const Section, Ident: string; Default: Boolean): Boolean;</div><div>var</div><div> s: string;</div><div>begin</div><div> Result := Default;</div><div> s := ReadString(Section, Ident, '');</div><div> if s > '' then</div><div> Result := SysUtils.StrToBoolDef(s[1], False);</div><div>end;</div></div><div><br></div><div>And, instead of:</div><div><br></div><div><div>procedure TCustomIniFile.WriteBool(const Section, Ident: string; Value: Boolean);</div><div>begin</div><div> WriteString(Section, Ident, BoolToChar(Value));</div><div>end;</div></div><div><br></div><div>Could be:</div><div><br></div><div><div>procedure TCustomIniFile.WriteBool(const Section, Ident: string; Value: Boolean);</div><div>begin</div><div> WriteString(Section, Ident, SysUtils.BoolToStr(Value, True));</div><div>end;</div></div><div><br></div><div>So I could use with:</div><div><br></div><div><div>initialization</div><div> SetLength(SysUtils.TrueBoolStrs, 1);</div><div> SetLength(SysUtils.FalseBoolStrs, 1);</div><div> SysUtils.TrueBoolStrs[0] := 'true'; // or other</div><div> SysUtils.FalseBoolStrs[0] := 'false'; // or other</div></div><div><br></div><div>Just ideas hehe..<br></div><span class=""><div><br></div>--<br>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</span></div></div>
<br>_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br></blockquote></div><br></div>