From d4117aeb341a8becd5e4663b13fce3691bb776fc Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 7 Aug 2004 16:56:28 +0000 Subject: [PATCH] + TryStrToInt* added --- rtl/objpas/sysutils/sysstr.inc | 26 +++++++++++++++++++++++--- rtl/objpas/sysutils/sysstrh.inc | 9 +++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/rtl/objpas/sysutils/sysstr.inc b/rtl/objpas/sysutils/sysstr.inc index 8aedebdc26..0093080a9a 100644 --- a/rtl/objpas/sysutils/sysstr.inc +++ b/rtl/objpas/sysutils/sysstr.inc @@ -655,6 +655,14 @@ begin end ; {$ENDIF} + +function TryStrToInt(const s: string; var i : integer) : boolean; +var Error : word; +begin + Val(s, i, Error); + TryStrToInt:=Error=0 +end; + { StrToInt converts the string S to an integer value, if S does not represent a valid integer value EConvertError is raised } @@ -680,7 +688,16 @@ var Error: word; begin Val(S, result, Error); if Error <> 0 then raise EConvertError.createfmt(SInValidInteger,[S]); -end ; +end; + + +function TryStrToInt64(const s: string; var i : int64) : boolean; +var Error : word; +begin + Val(s, i, Error); + TryStrToInt64:=Error=0 +end; + { StrToIntDef converts the string S to an integer value, @@ -2175,7 +2192,10 @@ const { $Log$ - Revision 1.13 2004-06-13 10:49:50 florian + Revision 1.14 2004-08-07 16:56:28 florian + + TryStrToInt* added + + Revision 1.13 2004/06/13 10:49:50 florian * fixed some bootstrapping problems as well as some 64 bit stuff Revision 1.12 2004/06/12 13:57:18 michael @@ -2272,4 +2292,4 @@ const instead of direct comparisons of low/high values of orddefs because qword is a special case -} +} \ No newline at end of file diff --git a/rtl/objpas/sysutils/sysstrh.inc b/rtl/objpas/sysutils/sysstrh.inc index 8df2144d48..a091b96b3a 100644 --- a/rtl/objpas/sysutils/sysstrh.inc +++ b/rtl/objpas/sysutils/sysstrh.inc @@ -118,8 +118,10 @@ function IntToStr(Value: QWord): string; function IntToHex(Value: integer; Digits: integer): string; function IntToHex(Value: Int64; Digits: integer): string; function StrToInt(const s: string): integer; +function TryStrToInt(const s: string; var i : integer) : boolean; {$IFNDEF VIRTUALPASCAL} function StrToInt64(const s: string): int64; +function TryStrToInt64(const s: string; var i : int64) : boolean; {$ENDIF} function StrToIntDef(const S: string; Default: integer): integer; {$IFNDEF VIRTUALPASCAL} @@ -190,7 +192,10 @@ function BCDToInt(Value: integer): integer; { $Log$ - Revision 1.7 2004-06-20 20:42:37 florian + Revision 1.8 2004-08-07 16:56:28 florian + + TryStrToInt* added + + Revision 1.7 2004/06/20 20:42:37 florian * fixed bootstrapping problems Revision 1.6 2004/06/13 10:49:50 florian @@ -255,4 +260,4 @@ function BCDToInt(Value: integer): integer; instead of direct comparisons of low/high values of orddefs because qword is a special case -} +} \ No newline at end of file