1. Home
  2. Computing & Technology
  3. Delphi Programming
GlossaryTips/Tricks|FREE App/VCL|Essentials|Books|Link Back

Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
 

StrToBool

unit
SysUtils
category
type conversion routines

declaration
function StrToBool(const s : string): boolean;

description
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.

example
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!!
*)

in real code

see also
TryStrToBool, IntToStr, SetLength, BoolToStr, StrToBoolDef


 Free Delphi code snippet inside every Delphi Newsletter!
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.