Hi!

Am Sonntag, den 23.11.2008, 14:18 -0200 schrieb Felipe Monteiro de
Carvalho:
> Hello,
> 
> I would like to verify if a string is a valid number, as in StrToInt
> will work when applied to it. The obvious way is making a try
> statement:
> 
>       try
>         StrToInt(TokenStr);
>         AdicionarToken(tNumeroLiteral, TokenStr);
>       except
>         AdicionarToken(tId, TokenStr);
>       end;
> 
> but I don't like this solution, because a lot of exceptions will be
> caused by normal execution of my program, which will disturb debugging
> it ...

Always avoid exceptions if possible, since they are very costly in terms
CPU time. Do your error handling with exceptions, but not routine tests.
This would be misuse of exceptions.

For your problem just use the original Pascal procedure
  Val(St:String;Var Value,Position:Integer)
which simply returns the position of an illegal character or 0 if the
string was a legal number.

Bye
  Hansi


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to