Re: [fpc-pascal] BoolToStr

2022-09-01 Thread Zeljko Avramovic via fpc-pascal
> > You can use
>
> BoolToStr(b,'TRUE','FALSE')
>
> That works great!  Shouldn't that be the default and you can put in
> something else if you want it?

Latest trunk allows you this if you include new syshelpers unit:

True.ToString;  // True
True.ToTrueFalseString(scfUpperCase);   // TRUE
True.ToString('OnState', 'OffState');   // OnState
True.ToString('Running', 'Stopped', scfUpperCase);  // RUNNING

It also allows you to populate TBitFormatSettings with your strings for TRUE 
and FALSE and gives you method CopyToDefaultBoolStrings. This changes boolean 
to string text outputs in syshelpers and some other places. Maybe that could 
fit your bill.

More info can be found in this demo:
https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/rtl-objpas/examples/syshelpersdemo.pas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-29 Thread Michael Van Canneyt via fpc-pascal




On Mon, 29 Aug 2022, James Richters via fpc-pascal wrote:


Thanks for the discussion everyone, it does shed some light on what's
going on.  I agree it would be impossible to change it now, It was
actually a GREAT idea to make it customizable, and that serves my needs
just fine.  I guess all that's left is to update the documentation to show
what it really does and show how it is customizable.  I wouldn't mind
doing that...  if I knew how.  What is the proper method to submit
documentation change requests?


I already updated the documentation.

Will be visible tomorrow in the daily snapshot of the docs.

However, for future reference:
The proper procedure is to submit a patch in the issue tracker:
https://gitlab.com/freepascal.org/fpc/documentation
(if you look at the last commit on that page, you'll see it is the update of
BoolToStr)

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-29 Thread James Richters via fpc-pascal
Thanks for the discussion everyone, it does shed some light on what's going on. 
  I agree it would be impossible to change it now, It was actually a GREAT idea 
to make it customizable, and that serves my needs just fine.  
I guess all that's left is to update the documentation to show what it really 
does and show how it is customizable.   I wouldn't mind doing that... if I knew 
how.  What is the proper method to submit documentation change requests?

James  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-29 Thread Nikolay Nikolov via fpc-pascal


On 8/29/22 11:33, Jean SUZINEAU via fpc-pascal wrote:

Le 29/08/2022 à 01:41, James Richters via fpc-pascal a écrit :
If a special function is needed for some COM thing or weird Winapi 
thing, then that function should be part of the unit that needs it, 
not modifying the generic function intended to be used for general 
purpose applications output something that does not conform to other 
Pascal Boolean datatypes and just confuses everyone.
Unfortunately, it's not just a few windows functions which use this 
behaviour but the whole Windows API:


https://docs.microsoft.com/fr-fr/windows/win32/api/winuser/nf-winuser-getmessage?redirectedfrom=MSDN 



The Microsoft BOOL datatype uses this convention so the whole 
ecosystem is attracted to use it (other C program on windows, Delphi, 
... )


I imagine it's more efficient at the assembler level to process the 
result of functions returning boolean.


Or, it could be related to the (Visual) BASIC language. BASIC represents 
false as 0 and true as -1, and Microsoft have been a major developer of 
BASIC interpreters and compilers ever since their beginning. My guess 
is, they used -1 to ensure better interoperability between Visual C++ 
and Visual Basic.


Nikolay

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-29 Thread Jean SUZINEAU via fpc-pascal

Le 29/08/2022 à 01:41, James Richters via fpc-pascal a écrit :

If a special function is needed for some COM thing or weird Winapi thing, then 
that function should be part of the unit that needs it, not modifying the 
generic function intended to be used for general purpose applications output 
something that does not conform to other Pascal Boolean datatypes and just 
confuses everyone.
Unfortunately, it's not just a few windows functions which use this 
behaviour but the whole Windows API:


https://docs.microsoft.com/fr-fr/windows/win32/api/winuser/nf-winuser-getmessage?redirectedfrom=MSDN

The Microsoft BOOL datatype uses this convention so the whole ecosystem 
is attracted to use it (other C program on windows, Delphi, ... )


I imagine it's more efficient at the assembler level to process the 
result of functions returning boolean.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-29 Thread Michael Van Canneyt via fpc-pascal




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


I'm curious if there is a way to search the FPC version history of changes
for BoolToStr to see why it was changed, and see if there is a valid
reason not to change it back.  it was obviously changed from the way the
documentations is at some point.  It really seems to me that if it was
that important that someone had a function that output a 0 or a -1, the
only way it makes sense is if it's an integer, not a string.


The reason is Delphi compatibility.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-28 Thread Sven Barth via fpc-pascal

Am 29.08.2022 um 01:41 schrieb James Richters via fpc-pascal:

I'm curious if there is a way to search the FPC version history of changes for 
BoolToStr to see why it was changed, and see if there is a valid reason not to 
change it back. it was obviously changed from the way the documentations is at 
some point.  It really seems to me that if it was that important that someone 
had a function that output a 0 or a -1, the only way it makes sense is if it's 
an integer, not a string.
This was done in 2006 (commit 
https://gitlab.com/freepascal.org/fpc/source/-/commit/4264f5d0414 ) for 
Delphi compatibility and thus there is *no valid reason* to change it back.


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-28 Thread James Richters via fpc-pascal
I don't see how it makes anything compatible at all.. because it's NOT a 0 or a 
-1 integer value,  it's a STRING of '0' or '-1' so you can't even evaluate the 
negative bit.. because there isn't one, it's a string of - and 1.   You would 
have to do StrToInt(BoolToStr(MyVariable)) to be able to evaluate the negative 
bit... which again is useless because there is only one bit to check.. indeed 
you would need to do  StrToInt(BoolToStr(MyVariable)) just to evaluate the 0 as 
a numeric value, but then this is a really round about way to do it when you 
could make a simple BoolToInt function to just give you the numeric result.

Even if it is convenient to set the - flag for "All Bits Set"  it doesn't apply 
to BoolToStr, because we aren't evaluating a Nibble, or a Byte, or a Word, etc, 
we are only evaluating a single bit Boolean variable.. so there are no, ALL 
Bits, there is only THE Bit.  I guess technically ALL one of it was set... but 
making it a -1 makes it more difficult to stack a bunch of these bits together 
into a word or something, and the - really serves no purpose if there is only 
one bit.. in fact you can't even put it into a byte because -1 isn't a valid 
Byte.  You would have to do MyByte:=Abs(StrToInt(BoolToStr(True)));

I think it would be best to make BoolToStr always produce 'TRUE' or 'FALSE' as 
the default because that is what is documented, and that is also what makes the 
most sense.. after all you are asking for a STRING, so you are outputting to 
something that wants a String, probably to be readable at some point, if you do 
Writeln of a Boolean you get 'TRUE' or 'FALSE', and BoolToStr should do that 
same thing... just like the documentation indicates.  

An additional BoolToInt could be added that returned an integer, which I think 
should return a 0 or a 1, but maybe retain the ability to customize the integer 
output the same way BoolToStr does, then if you want to check the - flag 
instead of checking the 1 bit, you could do that.. as silly as it is for a 1 
bit test. 

Anyway, I suppose such a change would break a whole pile of stuff at this 
point, so it's probably not going to happen... but it would be nice if it made 
more logical sense, and BoolToInt is what you need if you want to get a 0 and 1 
(or 0 and -1 as the case may be) numerical value, but there doesn't appear to 
be one in FPC.

I'm curious if there is a way to search the FPC version history of changes for 
BoolToStr to see why it was changed, and see if there is a valid reason not to 
change it back. it was obviously changed from the way the documentations is at 
some point.  It really seems to me that if it was that important that someone 
had a function that output a 0 or a -1, the only way it makes sense is if it's 
an integer, not a string. 

If a special function is needed for some COM thing or weird Winapi thing, then 
that function should be part of the unit that needs it, not modifying the 
generic function intended to be used for general purpose applications output 
something that does not conform to other Pascal Boolean datatypes and just 
confuses everyone.

James


Op 8/28/2022 om 8:45 PM schreef Ralf Quint via fpc-pascal:
On 8/28/2022 8:23 AM, James Richters via fpc-pascal wrote:
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
Very logical in fact. 0 is NO bit set in any given size of boolean data type, 
-1 means ALL bits set on that same size boolean data type.  
Pascal boolean datatypes only have 0 or 1 as defined values.  But probably it 
is for some COM or Winapi compatible purpose.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-28 Thread Marco van de Voort via fpc-pascal


Op 8/28/2022 om 8:45 PM schreef Ralf Quint via fpc-pascal:

On 8/28/2022 8:23 AM, James Richters via fpc-pascal wrote:

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


Very logical in fact. 0 is NO bit set in any given size of boolean 
data type, -1 means ALL bits set on that same size boolean data type.


Pascal boolean datatypes only have 0 or 1 as defined values.  But 
probably it is for some COM or Winapi compatible purpose.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-28 Thread James Richters via fpc-pascal
> You can use

BoolToStr(b,'TRUE','FALSE')

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

James.



-Original Message-
From: fpc-pascal  On Behalf Of
Michael Van Canneyt via fpc-pascal
Sent: Sunday, August 28, 2022 11:39 AM
To: ja...@productionautomation.net; FPC-Pascal users discussions

Cc: Michael Van Canneyt ; James Richters

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

I will adapt the documentation to be more precies.

You can use

BoolToStr(b,'TRUE','FALSE')

or
BoolToStr(b,True)

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.

Use

Ord(Boolean)

It will give you 0 and 1.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-28 Thread Ralf Quint via fpc-pascal

On 8/28/2022 8:23 AM, James Richters via fpc-pascal wrote:

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


Very logical in fact. 0 is NO bit set in any given size of boolean data 
type, -1 means ALL bits set on that same size boolean data type. And a 
check on TRUE or FALSE, can easily be done with checking the sign flag 
of a processor rather than doing actually any bit fiddling (at least on 
those CPUs that I am familiar with).


Ralf

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr

2022-08-28 Thread Michael Van Canneyt via fpc-pascal




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


I will adapt the documentation to be more precies.

You can use

BoolToStr(b,'TRUE','FALSE')

or 
BoolToStr(b,True)


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.

Use

Ord(Boolean)

It will give you 0 and 1.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] BoolToStr

2022-08-28 Thread James Richters via fpc-pascal
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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-27 Thread Michael Van Canneyt



On Fri, 26 Jun 2009, Giuliano Colla wrote:


Graeme Geldenhuys ha scritto:
Again, nothing like this is hinted at in the documentation. I'll double 
check on Monday what the Kylix 3 help says regarding BoolToStr and 
StrToBool and localization and when it should actually be used.



Kylix 3 help on TrueBoolStrs variable specifies:
quote
When using the BoolToString function, true values are converted to the first 
string of the list. When using the StrToBool function, any string in the list 
is converted to true.

/quote
The same for FalseBoolStrs variable, of course.

Apparently the mechanism is intended to convert from human understandable or 
localized strings to standardized TRUE/FALSE strings. The opposite of what 
you needed. No wonder it fails for you.


But there is a bug in strtobool: it does not check all elements in the list.
(in fact, none) So that must be fixed.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Graeme Geldenhuys
Hi,

I'm busy translating our projects. fpGUI Toolkit uses it's own
translation via .po files (similar to Lazarus projects). But now there
are some output that is not being translated because it is output from
the RTL. One such case is the output of BoolToStr().

How am I supposed to translate that, or must I implement my own
fpgBoolToStr() to fpGUI project?

My default locale is en_ZA.UTF-8.  Normally if I change the LANG
environment variable, my fpGUI based projects look for those language
translation .po files and if none is found, it reverts to the default
compiled locale (normally English, but other languages can be selected
as default)


  Console output ==
$ ./project1
True
False

$ export LANG=af_ZA

$ ./project1
True
False

$ locale
LANG=af_ZA
LC_CTYPE=af_ZA
LC_NUMERIC=af_ZA
LC_TIME=en_DK.UTF-8
LC_COLLATE=af_ZA
LC_MONETARY=af_ZA
LC_MESSAGES=af_ZA
LC_PAPER=af_ZA
LC_NAME=af_ZA
LC_ADDRESS=af_ZA
LC_TELEPHONE=af_ZA
LC_MEASUREMENT=af_ZA
LC_IDENTIFICATION=af_ZA
LC_ALL=

==



=  project1.pas  ===
program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, Sysutils;

var
  b: Boolean;
begin
  b := True;
  writeln(BoolToStr(b, True));
  b := False;
  writeln(BoolToStr(b, True));
end.



Regards,
  - Graeme -

___
fpGUI - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Michael Van Canneyt



On Fri, 26 Jun 2009, Graeme Geldenhuys wrote:


Hi,

I'm busy translating our projects. fpGUI Toolkit uses it's own
translation via .po files (similar to Lazarus projects). But now there
are some output that is not being translated because it is output from
the RTL. One such case is the output of BoolToStr().

How am I supposed to translate that, or must I implement my own
fpgBoolToStr() to fpGUI project?


No. The Boolean strings are exposed in from the sysutils unit,
see TrueBoolStr, FalseBoolStr. The first string in those arrays
is used. If there are no elements in those arrays, they are 
initialized with 'True' and 'False'.


So all you need to do is initialize them with the localized versions
prior to the first call of BoolToStr().

Michael.



My default locale is en_ZA.UTF-8.  Normally if I change the LANG
environment variable, my fpGUI based projects look for those language
translation .po files and if none is found, it reverts to the default
compiled locale (normally English, but other languages can be selected
as default)


  Console output ==
$ ./project1
True
False

$ export LANG=af_ZA

$ ./project1
True
False

$ locale
LANG=af_ZA
LC_CTYPE=af_ZA
LC_NUMERIC=af_ZA
LC_TIME=en_DK.UTF-8
LC_COLLATE=af_ZA
LC_MONETARY=af_ZA
LC_MESSAGES=af_ZA
LC_PAPER=af_ZA
LC_NAME=af_ZA
LC_ADDRESS=af_ZA
LC_TELEPHONE=af_ZA
LC_MEASUREMENT=af_ZA
LC_IDENTIFICATION=af_ZA
LC_ALL=

==



=  project1.pas  ===
program project1;

{$mode objfpc}{$H+}

uses
 {$IFDEF UNIX}{$IFDEF UseCThreads}
 cthreads,
 {$ENDIF}{$ENDIF}
 Classes, Sysutils;

var
 b: Boolean;
begin
 b := True;
 writeln(BoolToStr(b, True));
 b := False;
 writeln(BoolToStr(b, True));
end.



Regards,
 - Graeme -

___
fpGUI - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Graeme Geldenhuys
Michael Van Canneyt wrote:
 
 So all you need to do is initialize them with the localized versions
 prior to the first call of BoolToStr().

Thanks Michael.  Now the other obvious question, why is TrueBoolStrs and
FalseBoolStrs array types?  Why not simply of type String?


  SetLength(TrueBoolStrs,1);
  TrueBoolStrs[0] := 'Waar';

  SetLength(FalseBoolStrs,1);
  FalseBoolStrs[0] := 'Onwaar';


Looking at the implementation of BoolToStr(), it only ever uses the
first element. Reading the fpdoc help on BoolToStr and FalseBoolStrs it
doesn't mention anything about why the are defined as arrays and what
the other elements (if more than one) is used for.


Regards,
  - Graeme -

___
fpGUI - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Michael Van Canneyt



On Fri, 26 Jun 2009, Graeme Geldenhuys wrote:


Michael Van Canneyt wrote:


So all you need to do is initialize them with the localized versions
prior to the first call of BoolToStr().


Thanks Michael.  Now the other obvious question, why is TrueBoolStrs and
FalseBoolStrs array types?  Why not simply of type String?


 SetLength(TrueBoolStrs,1);
 TrueBoolStrs[0] := 'Waar';

 SetLength(FalseBoolStrs,1);
 FalseBoolStrs[0] := 'Onwaar';


Looking at the implementation of BoolToStr(), it only ever uses the
first element. Reading the fpdoc help on BoolToStr and FalseBoolStrs it
doesn't mention anything about why the are defined as arrays and what
the other elements (if more than one) is used for.


StrToBool should use all elements ?

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Graeme Geldenhuys
Michael Van Canneyt wrote:
 
 StrToBool should use all elements ?

In FPC 2.2.5 it does not.

 implementation  =
begin
 if UseBoolStrs Then
  begin
CheckStrs;
if B then
  Result:=TrueBoolStrs[0]
else
  Result:=FalseBoolStrs[0];
  end
 else
  If B then
Result:='-1'
  else
Result:='0';
end;
==


Regards,
  - Graeme -

___
fpGUI - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Graeme Geldenhuys
Michael Van Canneyt wrote:
 
 StrToBool should use all elements ?

In FPC 2.3.x (latest trunk) in also doesn't. Looks indentical to 2.2.5


Regards,
  - Graeme -

___
fpGUI - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Vincent Snijders

Graeme Geldenhuys schreef:

Michael Van Canneyt wrote:

StrToBool should use all elements ?


In FPC 2.2.5 it does not.

 implementation  =
begin
 if UseBoolStrs Then
  begin
CheckStrs;
if B then
  Result:=TrueBoolStrs[0]
else
  Result:=FalseBoolStrs[0];
  end
 else
  If B then
Result:='-1'
  else
Result:='0';
end;
==


Please add the declaration, to make sure it is StrToBool

Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Graeme Geldenhuys
Vincent Snijders wrote:
 
 Please add the declaration, to make sure it is StrToBool

I'm not that blind. :-)  And the function in question in BoolToStr().
But now that you mention StrToBool(), that is even worse, it hard-codes
the 'FALSE' and 'TRUE' and doesn't even use the arrays.

How come nobody ever noticed this? Does everybody only write English
programs. :-)

==
function BoolToStr(B: Boolean;UseBoolStrs:Boolean=False): string;

procedure CheckStrs;
begin
If Length(TrueBoolStrs)=0 then
  begin
SetLength(TrueBoolStrs,1);
TrueBoolStrs[0]:='True';
  end;
If Length(FalseBoolStrs)=0 then
  begin
SetLength(FalseBoolStrs,1);
FalseBoolStrs[0]:='False';
  end;
end;

begin
 if UseBoolStrs Then
  begin
CheckStrs;
if B then
  Result:=TrueBoolStrs[0]
else
  Result:=FalseBoolStrs[0];
  end
 else
  If B then
Result:='-1'
  else
Result:='0';
end;


==

function TryStrToBool(const S: string; out Value: Boolean): Boolean;
Var
  Temp : String;
  D : Double;
  Code: word;
begin
  Temp:=upcase(S);
  Val(temp,D,code);
  Result:=true;
  If Code=0 then
Value:=(D0.0)
  else If Temp='TRUE' then
Value:=true
  else if Temp='FALSE' then
Value:=false
  else
Result:=false;
end;

==



Regards,
  - Graeme -

___
fpGUI - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Vincent Snijders

Graeme Geldenhuys schreef:

Vincent Snijders wrote:

Please add the declaration, to make sure it is StrToBool


I'm not that blind. :-)  And the function in question in BoolToStr().
But now that you mention StrToBool(), that is even worse, it hard-codes


I did not mention StrToBool first, Michael did, and you seemed to ignore 
that.


Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Henry Vermaak
2009/6/26 Graeme Geldenhuys grae...@opensoft.homeip.net:

 How come nobody ever noticed this? Does everybody only write English
 programs. :-)

Because it's so simple/trivial that everyone rolls their own for user
interfaces?  I know I do.

Henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Henry Vermaak
2009/6/26 Vincent Snijders vsnijd...@vodafonevast.nl:
 Graeme Geldenhuys schreef:

 How come nobody ever noticed this? Does everybody only write English
 programs. :-)


 Because I always thought these function were not for users, but for systems,
 for example to store a boolean in a xml file or to create an adhoc dynamic
 SQL query. You would not want to have those strings translated (unless it an
 MS-Access system of last century).

I think even for config/system files they are useless, since it's a
lot more friendly to support yes/no, true/false and on/off, not just
true/false.  I presume these functions are there for Delphi
compatibility?

Henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Graeme Geldenhuys

Vincent Snijders wrote:


I did not mention StrToBool first, Michael did, and you seemed to ignore 
that.


Sorry, that one slipped by me unnoticed



Regards,
- Graeme -


fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Graeme Geldenhuys

Vincent Snijders wrote:


Because I always thought these function were not for users, but for 
systems, for example to store a boolean in a xml file or to create an 


Your example is a good one and I agree there, but I do think it's for users to. 
For example, the whole reason I noticed the translation issue, was in my 
TStringGrid mediator. I displayed records (actually objects) that have a 
IsActive boolean property. The display mediator I use translates booleans to 
strings, displays TDateTime in the user specific format, displays TDateTime = 0 
(ridiculous 1899-12-30 date) into something more user understandable, displays 
currencies as the users specified etc... Anyway, all worked except for the 
English True/False strings (from TTaxRate.IsActive property) return by 
BoolToStr() which should have been in Afrikaans. Or at least I expected it to 
be in Afrikaans or whatever other locale was active.


Regards,
- Graeme -


fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Graeme Geldenhuys

Henry Vermaak wrote:


I think even for config/system files they are useless, since it's a
lot more friendly to support yes/no, true/false and on/off, not just
true/false.


Maybe that was the idea behind the TrueBoolStrs array. Element 0 is true/false, 
element 1 maybe yes/no, element 3 maybe on/off?  Either way, I did not find 
any documentation why there is an array used or what should actually be in it. 
The implementation of BoolToStr and StrToBool does give any clues either, 
because they always use element 0 or a hardcoded string value in English.

So I take it you agree with Vincent, that I should basically never user 
BoolToStr or StrToBool for user displayed values and rather duplicate the code 
in my own application which supports translated values?  And then use the 
SysUtils version for config files or database stored value?
Again, nothing like this is hinted at in the documentation. I'll double check 
on Monday what the Kylix 3 help says regarding BoolToStr and StrToBool and 
localization and when it should actually be used.

Regards,
- Graeme -


fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread John Coppens
On Fri, 26 Jun 2009 15:54:55 +0100
Henry Vermaak henry.verm...@gmail.com wrote:

  How come nobody ever noticed this? Does everybody only write English
  programs. :-)

I _hate_ to think of the consequences of localization of those strings.
Have we had enough of the . and , problem? I don't think we need another
cause for incompatibilities in data files. Localization should be done by
the application program which assigns a meaning to the variable, not by
Pascal.

Boolean values tend to represent too many things, apart from TRUE and
FALSE. Like FULL and EMPTY, FAST and SLOW, and so on. To me it makes
sense that booleans are stored as bits, and, if _really_ necessary, shown
as TRUE or FALSE, mainly for debugging purposes. Wirth's Pascal definition
specifies the use of TRUE and FALSE.

Just my $.02

John
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] BoolToStr() with correct locale output

2009-06-26 Thread Giuliano Colla

Graeme Geldenhuys ha scritto:
Again, nothing like this is hinted at in the documentation. I'll double 
check on Monday what the Kylix 3 help says regarding BoolToStr and 
StrToBool and localization and when it should actually be used.



Kylix 3 help on TrueBoolStrs variable specifies:
quote
When using the BoolToString function, true values are converted to the 
first string of the list. When using the StrToBool function, any string 
in the list is converted to true.

/quote
The same for FalseBoolStrs variable, of course.

Apparently the mechanism is intended to convert from human 
understandable or localized strings to standardized TRUE/FALSE strings. 
The opposite of what you needed. No wonder it fails for you.


--
Giuliano Colla

Whenever people agree with me, I always feel I must be wrong (O. Wilde)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] booltostr, compability issue

2006-12-29 Thread Marco van de Voort

I just fixed booltostr in 2.1.1 to be D7 compat. 

This is one of the stupidest Delphi changes I ever saw, but anyway,
compability is compability.

Booltostr now returns -1 and 0, and only True and False if you pass
true to the 2nd parameter which is default false.  You can influence the
outcome via the new trueboolstr and falseboolstr dynarrays.

So people suddenly having problems with e.g. own customing streaming or
exporting systems in 2.1.1, check if you use booltostr and replace it with a
(trivial) own implementation.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal