Convert Boolean to String with Inno Installation

What is the easiest way to convert a boolean to a string in an Inno Setup Pascal script? This trivial task, which should be completely implicit, seems to require a full-blown if / else .

 function IsDowngradeUninstall: Boolean; begin Result := IsCommandLineParamSet('downgrade'); MsgBox('IsDowngradeUninstall = ' + Result, mbInformation, MB_OK); end; 

This does not work because the "Type of mismatch." IntToStr does not accept a Boolean . BoolToStr does not exist.

+5
source share
2 answers

If you need it only once, the simplest built-in solution is to drop the Boolean to Integer and use the IntToStr function . You will get 1 for True and 0 for False .

 MsgBox('IsDowngradeUninstall = ' + IntToStr(Integer(Result)), mbInformation, MB_OK); 

Although I usually use the Format function for the same result:

 MsgBox(Format('IsDowngradeUninstall = %d', [Result]), mbInformation, MB_OK); 

(Unlike Delphi) The Inno Setup / Pascal Script Format program implicitly converts Boolean to Integer for %d .


If you need a more bizarre conversion or need frequent conversion, do your own function, as @RobeN already shows in your answer.

 function BoolToStr(Value: Boolean): String; begin if Value then Result := 'Yes' else Result := 'No'; end; 
+15
source
 [Code] function BoolToStr(Value : Boolean) : String; begin if Value then result := 'true' else result := 'false'; end; 

or

 [Code] function IsDowngradeUninstall: Boolean; begin Result := IsCommandLineParamSet('downgrade'); if Result then MsgBox('IsDowngradeUninstall = True', mbInformation, MB_OK) else MsgBox('IsDowngradeUninstall = False', mbInformation, MB_OK); end; 
+2
source

Source: https://habr.com/ru/post/1241624/


All Articles