[fpc-pascal] BoolToStr
James Richters
james.richters at productionautomation.net
Sun Aug 28 17:23:25 CEST 2022
I'm generating a report where I wish to display some Boolean values. I
thought I would try BoolToStr, as according to:
https://www.freepascal.org/docs-html/rtl/sysutils/booltostr.html it states:
Description
BoolToStr converts the boolean B to one of the strings 'TRUE' or 'FALSE'
So it should do exactly what I want. output the text string 'TRUE' or
'FALSE' depending on the Boolean state,
but that is not what happens:
Uses Sysutils;
Begin
Writeln(BooltoStr(True));
Writeln(BooltoStr(False));
End.
Running "i:\booltostr.exe "
-1
0
Why true is -1 instead of 1 is beyond me, but anyway, I would consider this
BoolToInt, not BoolToStr, I want the Strings 'TRUE' or 'FALSE' as indicated
in the documentation
And BoolToInt should always output 0 or 1, not matter what operating system
you are on.. I don't understand the -1. I guess some Windows API's use -1
for true.. I still don't understand.
Maybe there should be a BoolToBit that could always be 0 or 1 regardless of
the operating system.
I know I can write my own simple function to do it the way I want, but why
does this behavior not match the documentation?
The whole point of having lots of little functions like FloatToStr, is so
everyone doesn't have to keep writing the same functions over and over.
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20220828/dde2a6e9/attachment-0001.htm>
More information about the fpc-pascal
mailing list