Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Boolean to String with Inno Setup

What is the easiest way to convert a Boolean value into a String in an Inno Setup Pascal script? This trivial task that should be completely implicit seems to require a full-blown if/else construction.

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

This doesn't work because "Type mismatch". IntToStr doesn't accept a Boolean neither. BoolToStr does not exist.

like image 613
ygoe Avatar asked Jan 27 '16 14:01

ygoe


People also ask

How to convert Boolean to string in Java?

How to Convert Boolean to String in Java? 1 Using valueOf () method#N#This method is directly used on String like String.valueOf () method to convert boolean value... 2 Using toString () method More ...

How to get the value of a Boolean in inttostr?

IntToStr doesn't accept a Boolean neither. BoolToStr does not exist. If you need it once only, the easiest inline solution is to cast the Boolean to Integer and use the IntToStr function. You get 1 for True and 0 for False.

How to convert a Boolean to an integer in Python?

BoolToStr does not exist. If you need it once only, the easiest inline solution is to cast the Boolean to Integer and use the IntToStr function. You get 1 for True and 0 for False. (Contrary to Delphi) The Inno Setup/Pascal Script Format implicitly converts the Boolean to Integer for %d.

How to convert a Boolean to an integer in Pascal?

IntToStr doesn't accept a Boolean neither. BoolToStr does not exist. If you need it once only, the easiest inline solution is to cast the Boolean to Integer and use the IntToStr function. You get 1 for True and 0 for False. (Contrary to Delphi) The Inno Setup/Pascal Script Format implicitly converts the Boolean to Integer for %d.


2 Answers

If you need it once only, the easiest inline solution is to cast the Boolean to Integer and use the IntToStr function. You get 1 for True and 0 for False.

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

Though, I usually use the Format function for the same result:

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

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


If you need a more fancy conversion, or if you need the conversion often, implement your own function, as @RobeN already shows in his answer.

function BoolToStr(Value: Boolean): String; 
begin
  if Value then
    Result := 'Yes'
  else
    Result := 'No';
end;
like image 156
Martin Prikryl Avatar answered Sep 28 '22 21:09

Martin Prikryl


[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; 
like image 34
RobeN Avatar answered Sep 28 '22 20:09

RobeN