2016-01-27 9 views
5

एक इनो सेटअप पास्कल स्क्रिप्ट में एक बूलियन मान को स्ट्रिंग में परिवर्तित करने का सबसे आसान तरीका क्या है? यह मामूली कार्य जो पूरी तरह से अंतर्निहित होना चाहिए, उसे if/else निर्माण की आवश्यकता होती है।इनो सेटअप के साथ बूलियन टू स्ट्रिंग को कनवर्ट करें

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

यह काम नहीं करता है क्योंकि "टाइप मिस्चैच"। IntToStrBoolean को स्वीकार नहीं करता है। BoolToStr मौजूद नहीं है।

उत्तर

14

आप इसे केवल एक बार, सबसे आसान इनलाइन समाधान Integer को Boolean डाली और IntToStr function उपयोग करने के लिए है की जरूरत है। आपको True और 0False के लिए 1 प्राप्त करें।

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

हालांकि, मैं आमतौर पर एक ही परिणाम के लिए Format function का उपयोग करें:

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

(डेल्फी के विपरीत) Inno सेटअप/पास्कल स्क्रिप्ट Format परोक्ष %d के लिए Integer को Boolean बदल देता है।


आप एक अधिक फैंसी रूपांतरण की जरूरत है, या यदि आप रूपांतरण अक्सर की जरूरत है, अपने खुद के समारोह को लागू, के रूप में @RobeN पहले से ही अपने जवाब में पता चलता है।

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

या

[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; 
संबंधित मुद्दे