Also in Delphi 6 and 7, you could use
function StrToIntDef(const S: string; const Default: Integer): Integer;
You The Default value is what you pass back if the StrToInt fails.
I.e. StrToIntDef('abc',-1) will return -1 , where as StrToIntDef('123',-
1) would return 123
HTH Jeremy
-----Original Message-----
From: "Paul Mckenzie" <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Date: Tue, 14 Oct 2003 09:15:17 +1300
Subject: Re: [DUG]: Handling exceptions
> This is in D6 HTH
>
> Converts a string that represents an integer (decimal or hex notation)
> to a
> number with Boolean success code.
>
> Unit
>
> SysUtils
>
> Category
>
> type conversion routines
>
> function TryStrToInt(const S: string; out Value: Integer): Boolean;
>
> Description
>
> TryStrToInt converts the string S, which represents an integer-type
> number
> in either decimal or hexadecimal notation, into a number, which is
> assigned
> to Value. If S does not represent a valid number, TryStrToInt returns
> False;
> otherwise TryStrToInt returns True.
> Regards
> Paul McKenzie
> Analyst Programmer
> SMSS Ltd.
>
> ----- Original Message -----
> From: "gajo" <[EMAIL PROTECTED]>
> To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
> Sent: Tuesday, October 14, 2003 8:52 AM
> Subject: [DUG]: Handling exceptions
>
>
> > Hi,
> >
> > I have to convert a string to integer. When a string is not correct,
> then
> > the StrToInt procedure raises an exception, and the user gets an
> error
> > message.
> >
> > I would like to prevent the error message from being displayed. How
> can I
> do
> > that?
> >
> > I was trying the following with no results:
> > try
> > a := StrToInt(Text);
> > except
> > on EConvertError do begin
> > Application.HandleException(Self);
> > ShowMessage('The user did not get the message')
> > end;
> > end
> >
> > Thanks, Gajo
> >
> >
> >
> >
> -----------------------------------------------------------------------
> ---
> -
> > New Zealand Delphi Users group - Delphi List -
> [EMAIL PROTECTED]
> > Website: http://www.delphi.org.nz
> > To UnSub, send email to: [EMAIL PROTECTED]
> > with body of "unsubscribe delphi"
> > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
> >
>
>
> -----------------------------------------------------------------------
> ----
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/