The Delphi function BoolToStr
converts a Boolean value to a string.
The result is either 'True'
or 'False'
, or 'numeric'
, '-1'
and '0'
respectively. Why is true
represented as '-1'
and not '1'
?
The source of these particular values is surely down to 0
and -1
being the values used by the COM boolean type.
Certainly in older versions of the Delphi RTL this function was used when converting variants from one type to another, so I'd be reasonably confident that COM variant support was the reason behind this decision.
You can see the remnants of that original code today in VariantChangeSimpleIntoSimple
found in System.VarUtils
. When asked to convert varBoolean
to varOleStr
it does:
VarOleStrFromStr(Dest, BoolToStr(LSource.VBoolean))
Further reading: