System.SysUtils.TryStrToBool

From Appmethod Libraries
Jump to: navigation, search

Object Pascal

function TryStrToBool(const S: string; out Value: Boolean): Boolean;

C++

extern DELPHI_PACKAGE bool __fastcall TryStrToBool(const System::UnicodeString S, /* out */ bool &Value)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

Converts a string to a Boolean value, with a Boolean success code.

TryStrToBool converts the string specified by S to a Boolean and sets Value to the result. If S can be converted to a number, TryStrToBool sets Value to False if that number is 0, True otherwise. If S cannot be converted to a number, TryStrToBool returns True if S is any of the strings listed in TrueBoolStrs (or differs from one only by case) and False if it is any of the strings listed in FalseBoolStrs (or differs from one only by case). If S is not a number and not one of the strings listed in TrueBoolStrs or FalseBoolStrs, TryStrToBool returns False to indicate that the conversion failed. If the conversion is successful, TryStrToBool returns True.

Note: If you do not assign a value to TrueBoolStrs, it is treated as if it contains the single string 'True'. Similarly, if you do not assign a value to FalseBoolStrs, it is treated as if it contains the single string 'False'.

Note: The TrueBoolStrs and FalseBoolStrs variables are undefined when an application starts. Any use of StrToBool, BoolToStr, or TryStrToBool will cause these variables to be initialised with the default values above.

See Also