[fpc-pascal] BoolToStr

James Richters james.richters at productionautomation.net
Sun Aug 28 21:14:17 CEST 2022

> You can use


That works great!  Shouldn't that be the default and you can put in
something else if you want it?  It's Boolean To String... not Bool to some
If I just do Writeln(True);  I get the string 'TRUE' 
The text 'TRUE' is what you get if you convert a Boolean value of 1 to a
string, not anything else.  

I guess the default must have been 'TRUE' or 'FALSE' at one time as that is
how the documentation is written, it must have been changed to be compatible
with Delphi code at some point I guess.

Thanks for the suggestion, it works for my needs.


-----Original Message-----
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of
Michael Van Canneyt via fpc-pascal
Sent: Sunday, August 28, 2022 11:39 AM
To: james at productionautomation.net; FPC-Pascal users discussions
<fpc-pascal at lists.freepascal.org>
Cc: Michael Van Canneyt <michael at freepascal.org>; James Richters
<james.richters at productionautomation.net>
Subject: Re: [fpc-pascal] BoolToStr

On Sun, 28 Aug 2022, James Richters via fpc-pascal wrote:

> 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
> 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

I will adapt the documentation to be more precies.

You can use



in which case it will use the BoolStrs arrays to determine the strings.

-1 and 0 are the Delphi values, which, I agree,  are not very intuitive.

> 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.

As said, the 0 and -1 are for Delphi compatibility.



It will give you 0 and 1.

fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org

More information about the fpc-pascal mailing list