Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi6 and StrToBool

119 views
Skip to first unread message

Sergey Gusev

unread,
Jul 31, 2001, 1:29:57 AM7/31/01
to

Hello.

function TryStrToBool(const S: string; out Value: Boolean): Boolean when in
it pass False in any time return false and it cause exception.

With best wishes, GSB.


Barry Kelly

unread,
Jul 31, 2001, 10:15:07 AM7/31/01
to
In article <3b66422b_2@dnews>
"Sergey Gusev" <g...@metacom.ru> wrote:

> function TryStrToBool(const S: string; out Value: Boolean): Boolean when in
> it pass False in any time return false and it cause exception.

I don't get an exception; however, I can confirm that there is a bug in
the routine:

function TryStrToBool(const S: string; out Value: Boolean): Boolean;
// ...
var
LResult: Extended;
begin
Result := TryStrToFloat(S, LResult);
if Result then
Value := LResult <> 0
else
begin
// Result is currently false, because S wasn't a float
VerifyBoolStrArray;
if CompareWith(TrueBoolStrs) then
Value := True
else if CompareWith(FalseBoolStrs) then
Value := False
else
Result := False;
// Result still false
end;
end;

If the string isn't a valid float, it will always return false.

-- Barry

--
If you're not part of the solution, you're part of the precipitate.
Team JEDI: http://www.delphi-jedi.org
NNQ - Quoting Style in Newsgroup Postings
http://web.infoave.net/~dcalhoun/nnq/nquote.html

K Wak

unread,
Aug 10, 2001, 3:26:40 PM8/10/01
to
: Barry Kelly <bar...@eircom.net> wrote:

>In article <3b66422b_2@dnews>
> "Sergey Gusev" <g...@metacom.ru> wrote:
>
>> function TryStrToBool(const S: string; out Value: Boolean): Boolean when in
>> it pass False in any time return false and it cause exception.
>
>I don't get an exception;

You will get the exception when StrToBool is used (which runs into the
bug in TryStrToBool).

Chris Morgan

unread,
Aug 23, 2001, 4:43:37 AM8/23/01
to
Any text string passed to the StrToBool function (which calls TryStrToBool)
causes an exception

b := StrToBool('true');
raises EConvertError

which is a very annoying bug.

"Barry Kelly" <bar...@eircom.net> wrote in message
news:a7fdmtognd11088v3...@4ax.com...

0 new messages