Bolean helper seems to be broke in 3.2.0 and down. lazarus / 21-General ---------------------------------------------------------------------- jamie · 2021-01-30 23:43 ABoolean.Tostring(True) should return a string of TRUE or FALSE, depending on the boolean's value. Instead it returns a numerical string. so the default is 0 or -1 Aboolean := True; Caption := Aboolean.Tostring; which shows as '-1'; Caption := Aboolean.Tostring(True);  is actually generating the value of the input parameter as a 0 or -1 and not the SELF.... Can any one else see this ? ---------------------------------------------------------------------- jamie · 2021-01-31 00:32 I noticed there is the TrueBoolStr array and FalseBoolStr array which are not set, So I set them but still they are not referenced ---------------------------------------------------------------------- Kays · 2021-01-31 00:47 Quote from: jamie on January 31, 2021, 12:43:03 am[…] Can any one else see this?Checking out tBooleanHelper’s documentation I saw the toString function uses a “new” Boolean-like type, an enumeration called tUseBoolStrs? That smells fishy. It turns out, writingCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i aBoolean.toString(tUseBoolStrs.true)does the trick. Obviously true is otherwise regarded as system.true, the Pascal’s actual Boolean type. There is only one other function that matches the function signature toString(Boolean): It’s the class function public class function tBooleanHelper.toString(Boolean, tUseBoolStrs = tUseBoolStrs.false). You’ve all the been calling the static function, not the instance version tBooleanHelper.toString(tUseBoolStrs). ---------------------------------------------------------------------- jamie · 2021-01-31 00:51 It sure is... Like they say in china... "Sum Ting Wong" EDIT  Looking at that, it's useless because it's too long winded... I can do better with a simple  Bools:Array[false..True] of String =('false','True'); Caption := Bools[True]; ---------------------------------------------------------------------- lucamar · 2021-01-31 02:38 It's all quite well explained in the docs. But if one doesn't like what the helper does, there is always BoolToStr() which can be used as: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Caption := BoolToStr(Aboolean, True); Which, IIRC, is what the helper does under the hood. ---------------------------------------------------------------------- PascalDragon · 2021-01-31 10:29 Quote from: Kays on January 31, 2021, 01:47:13 amQuote from: jamie on January 31, 2021, 12:43:03 am[…] Can any one else see this?Checking out tBooleanHelper’s documentation I saw the toString function uses a “new” Boolean-like type, an enumeration called tUseBoolStrs? That smells fishy. Complain to Embarcadero that they introduced it like this. Then again this way the compiler can differentiate between the static ToString and the instance one. ---------------------------------------------------------------------- Kays · 2021-01-31 11:47 Quote from: PascalDragon on January 31, 2021, 11:29:41 am[…] Complain to Embarcadero that they introduced it like this. Then again this way the compiler can differentiate between the static ToString and the instance one.Oh, no, no, no, no… Don’t tell me who complain to. Someone implemented it for our RTL. If Delphi now defined as part of the system unitCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  true = 42;we wouldn’t just blindly adapt it, too. It’s just a terrible idea to use false and true as identifiers. This Delphi-compatibility-frenzy is really annoying, you know. I’ve at least submitted a documentation improvement suggestion, so this issue jamie experienced is less likely to occur again. I would’ve tripped on it, too. ---------------------------------------------------------------------- jamie · 2021-01-31 13:31 So I guess its ok for a useless helper to do this...? ABool.ToString  would be 0 or -1, what ever the case is.. but this happens.. Abool.Tostring(True) is always a -1 string not a 'True' It states that the use of BoolToStr(Value, DoWeUseAStr?); does produce a 'True' or 'False' string but it also states the Helper uses the BoolToStr function when performing the act but it actually uses the input parameter as the value not the state of how to create the resulting string.. That is what I was trying to convey here.  of course it has been noted using the ENUM instead produces the correct value but that is long winded in code … something just isn't correct here no matter how you twist it. You should be able to indicate  if you want the product to be a 'True' or 'False' String as the results in short term but it just does not work that way.. I will check Delphi and get back with this. EDIT:  Absolutely useless feature..  Maybe I can overload the helper with an array type..  MyBoolean[true/false] should equal a string or 'True' or 'False' I've also noticed there is a TrueBoolStrs array and FalseBoolStrs array which are not defind but can be in the system unit. ---------------------------------------------------------------------- jamie · 2021-01-31 14:35 Ok , not exactly the same as I posted above but there is an example of a simple added member to the Boolean helper... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+}{$modeSwitch AdvancedRecords}{$ModeSwitch typehelpers}interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; typeTMyBooleanHelper = type Helper(TbooleanHelper) for Boolean Function LStr:string;End;   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  Caption := true.Lstr;end; Function TmyBooleanHelper.Lstr:String;Begin  Result := BoolToStr(Self, True);End;end.  You see the niceness in this ? its short and simple thus generates the literal string! ---------------------------------------------------------------------- lucamar · 2021-01-31 18:25 Quote from: jamie on January 31, 2021, 02:31:58 pmbut it also states the Helper uses the BoolToStr function when performing the act but it actually uses the input parameter as the value not the state of how to create the resulting string.. That is what I was trying to convey here. But the helper is really just a "proxy" for BoolToStr(): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function TBOOLHELPER.ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;begin  Result := BoolToStr(Self, UseBoolStrs=TUseBoolStrs.True);end;And it does work ... provided you don't forget that you must do: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AStr := SomeBool.ToString(TUseBoolStrs.True);cause a call like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AStr := SomeBool.ToString(True);will instead invoke the "class" method ... with UseBoolStrs = False (the default). I've also been bitten (more than once and more than twice!) by this kind of scoped enumerations and yes, they are a PITA. Here, though, it serves a clear purpose: to allow the compiler to differentiate between calls to the "class" function and to the method; it can't be done any easier way, AFAICT. ---------------------------------------------------------------------- jamie · 2021-01-31 18:32 My addition was to extend the useless helper and could still be used by those that wished it. When you are displaying Bools  in human readable form this is a nice way to do it , short and simple..  I really don't expect any one to parse Booleans that way.. ---------------------------------------------------------------------- PascalDragon · 2021-02-01 08:07 Quote from: Kays on January 31, 2021, 12:47:53 pmQuote from: PascalDragon on January 31, 2021, 11:29:41 am[…] Complain to Embarcadero that they introduced it like this. Then again this way the compiler can differentiate between the static ToString and the instance one.Oh, no, no, no, no… Don’t tell me who complain to. Someone implemented it for our RTL. Yes, I'm telling you that, because Delphi compatibility was the main reason they were added at all. And thus they were implemented in a Delphi compatible way and thus if you want to complain about the way they are implemented, complain with Embarcadero. Quote from: Kays on January 31, 2021, 12:47:53 pmIf Delphi now defined as part of the system unitCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  true = 42;we wouldn’t just blindly adapt it, too. It’s just a terrible idea to use false and true as identifiers. This Delphi-compatibility-frenzy is really annoying, you know Changing something existing and adding something new are two completely different topics. ---------------------------------------------------------------------- Kays · 2021-02-02 22:56 Quote from: PascalDragon on February 01, 2021, 09:07:36 amQuote from: Kays on January 31, 2021, 12:47:53 pmOh, no, no, no, no… Don’t tell me who complain to. Someone implemented it for our RTL. Yes, I'm telling you that, because Delphi compatibility was the main reason they were added at all. And thus they were implemented in a Delphi compatible way and thus if you want to complain about the way they are implemented, complain with Embarcadero.My point is nobody forced anyone to make things Delphi-compatible. Don’t get me wrong: I do support Delphi-compatibility, but within reason. IMO this is one occasion a prudent thinking person just should’ve said “No, we won’t do that.” Or, alternatively, our implementation is extended, enhanced in a way making it less likely to cause troubles, but I reckon there seems to be resistance even against that. I actually think FPC users migrating to Delphi is nothing to be concerned about. Quote from: PascalDragon on February 01, 2021, 09:07:36 amChanging something existing and adding something new are two completely different topics.I assumed we did not have a tBooleanHelper before Delphi did, did we? ---------------------------------------------------------------------- PascalDragon · 2021-02-03 08:12 Quote from: Kays on February 02, 2021, 11:56:19 pmQuote from: PascalDragon on February 01, 2021, 09:07:36 amQuote from: Kays on January 31, 2021, 12:47:53 pmOh, no, no, no, no… Don’t tell me who complain to. Someone implemented it for our RTL. Yes, I'm telling you that, because Delphi compatibility was the main reason they were added at all. And thus they were implemented in a Delphi compatible way and thus if you want to complain about the way they are implemented, complain with Embarcadero.My point is nobody forced anyone to make things Delphi-compatible. Don’t get me wrong: I do support Delphi-compatibility, but within reason. IMO this is one occasion a prudent thinking person just should’ve said “No, we won’t do that.” Or, alternatively, our implementation is extended, enhanced in a way making it less likely to cause troubles, but I reckon there seems to be resistance even against that. I actually think FPC users migrating to Delphi is nothing to be concerned about. But it's about Delphi users migrating to FPC. Quote from: Kays on February 02, 2021, 11:56:19 pmQuote from: PascalDragon on February 01, 2021, 09:07:36 amChanging something existing and adding something new are two completely different topics.I assumed we did not have a tBooleanHelper before Delphi did, did we? That's exactly what I'm saying?! We didn't have it before Delphi and thus we only added it for Delphi compatibility. If Delphi hadn't introduced a TBooleanHelper then we wouldn't have this discussion, cause we wouldn't have added it or would have added it differently (namely not as braindead). But as it was added for Delphi compatibility it is how it is. However changing something existing (like your example of True = 42), is something totally different and might be done not at all or maybe using some compatibility unit that's inserted transparently (like the ObjPas unit) or something like that. ---------------------------------------------------------------------- avra · 2021-02-03 13:19 With BitHelpers package you can do things like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   uses    bithelpers;  ...  procedure TForm1.BooleanBitTestBtnClick(Sender: TObject);  var    MyBool: boolean;  begin    MyBool := true;    Memo1.Append(MyBool.ToOneZeroString);    Memo1.Append(MyBool.ToOnOffString); // default is scfUnchangedCase and can be ommited    Memo1.Append(MyBool.ToOnOffString(scfLowerCase));  Memo1.Append(MyBool.ToTrueFalseString(scfUpperCase));    Memo1.Append(MyBool.ToString('OnState', 'OffState')); // true/false custom strings    Memo1.Append(MyBool.ToString('Укључено', 'Искључено', scfUpperCase)); // when case and unicode matter  end; Quote  1   On   on   TRUE   OnState   УКЉУЧЕНО