Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread StrToIntDef
Thu, Mar 7 2013 11:39 AMPermanent Link

Matthew Jones

What is the best way of implementing StrToIntDef in EWB?
(Can you tell I'm importing utility routines from Delphi?)

You have StrToInt but the help doesn't describe what happens if I pass it 'dog' as
a parameter.

/Matthew Jones/
Fri, Mar 8 2013 11:27 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< You have StrToInt but the help doesn't describe what happens if I pass it
'dog' as a parameter. >>

You'll get back NaN (not a number):

  ShowMessage(IntToStr(StrToInt('Dog')));

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Mar 11 2013 6:19 AMPermanent Link

Matthew Jones

Okay, I can work with that.

/Matthew Jones/
Mon, Mar 11 2013 11:06 AMPermanent Link

Matthew Jones

> You'll get back NaN (not a number):

For completeness (I was going to ask how to test for Nan), the WebDom unit includes
isNaN(), so the end result is:

function StrToIntDef(szValue : String; nDefault : Integer) : Integer;
begin
   Result := StrToInt(szValue);
   if isNaN(Result) then
       Result := nDefault;
end;



/Matthew Jones/
Mon, Mar 11 2013 1:59 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< For completeness (I was going to ask how to test for Nan), the WebDom
unit includes isNaN(), so the end result is: >>

I'll try to pop this in the WebCore unit in the next build.

Thanks,

Tim Young
Elevate Software
www.elevatesoft.com
Image