Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
function StrToBool(const s : string): boolean;
Returns a boolean from a string value, if *possible*.
While trying to convert a string to a boolean, StrToBool first tries to convert the string into a number; if the number is 0 the function returns False, True otherwise.
If s cannot be converted to a number, True is returned if S equals any of the strings in the TrueBoolStrs array; like wise False is returned if S equals any of the strings in the FalseBoolStrs.
Where FalseBoolStrs and TrueBoolStrs 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;
s := 'NO';
sT := '2003';
sF := '0';
sError := 'Not convertable';
SetLength(TrueBoolStrs,1);
SetLength(FalseBoolStrs,1);
TrueBoolStrs[0]:='YES';
FalseBoolStrs[0]:='NO';
(*
StrToBool(s) == False
StrToBool(sT) == True
StrToBool(sF) == False
StrToBool(sError) == EConvertError exception!!
*)
|
TryStrToBool,
IntToStr,
SetLength,
BoolToStr,
StrToBoolDef
|
Free Delphi code snippet inside every Delphi Newsletter! |
|
|
|
Got some code to share? Got a question? Need some help? |
|
|