Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
function TryStrToBool(const s : string; out b : boolean): boolean;
Converts a string to a boolean value with a Boolean success code.
If S can be converted to a number, TryStrToBool sets Value to false if that number is 0, true otherwise. If S cant 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.
Where FalseBoolStrs ('FALSE' by default) and TrueBoolStrs ('TRUE' by default) are global Delphi variables (dynamic string arrays) you can set and use when converting a boolean variable to string and back.
var s, sT, sF, sError : string;
b: boolean;
s := 'NO';
sT := '2003';
sF := '0';
sError := 'Not convertible';
SetLength(TrueBoolStrs,1);
SetLength(FalseBoolStrs,1);
TrueBoolStrs[0]:='YES';
FalseBoolStrs[0]:='NO';
(*
TryStrToBool(s, b) == False ; b == False
TryStrToBool(sT, b) == True; b == True
TryStrToBool(sF, b) == True; b == False
TryStrToBool(sError, b) == False!!
*)
|
StrToBool,
SetLength,
BoolToStr,
StrToBoolDef
|
Free Delphi code snippet inside every Delphi Newsletter! |
|
|
|
Got some code to share? Got a question? Need some help? |
|
|