From 1f3e00859140c7cad369a3cea6bbbf6f8cbfc0f4 Mon Sep 17 00:00:00 2001 From: mattias Date: Fri, 14 Dec 2018 08:44:08 +0000 Subject: [PATCH] rtl: system val integers support for hexnumbers --- packages/rtl/system.pas | 87 ++++++++--------------------------------- 1 file changed, 16 insertions(+), 71 deletions(-) diff --git a/packages/rtl/system.pas b/packages/rtl/system.pas index 2a20318..717e46e 100644 --- a/packages/rtl/system.pas +++ b/packages/rtl/system.pas @@ -476,11 +476,9 @@ end; function Number(S: String): Double; external name 'Number'; -procedure val(const S: String; out NI : NativeInt; out Code: Integer); - +function valint(const S: String; MinVal, MaxVal: NativeInt; out Code: Integer): NativeInt; var - x : double; - + x: double; begin Code:=0; x:=Number(S); @@ -495,8 +493,15 @@ begin end; if isNaN(x) or (X<>Int(X)) then Code:=1 + else if (xMaxVal) then + Code:=2 else - NI:=Trunc(x); + Result:=Trunc(x); +end; + +procedure val(const S: String; out NI : NativeInt; out Code: Integer); +begin + NI:=valint(S,low(NI),high(NI),Code); end; procedure val(const S: String; out NI: NativeUInt; out Code: Integer); @@ -512,96 +517,36 @@ begin end; procedure val(const S: String; out SI : ShortInt; out Code: Integer); -var - X:Double; begin - Code:=0; - x:=Number(S); - if isNaN(x) or (X<>Int(X)) then - Code:=1 - else if (xMaxShortInt) then - Code:=2 - else - SI:=Trunc(x); + SI:=valint(S,low(SI),high(SI),Code); end; procedure val(const S: String; out SI: smallint; out Code: Integer); - -var - x: double; begin - Code:=0; - x:=Number(S); - if isNaN(x) or (X<>Int(X)) then - Code:=1 - else if (xMaxSmallint) then - Code:=2 - else - SI:=Trunc(x); + SI:=valint(S,low(SI),high(SI),Code); end; procedure val(const S: String; out C: Cardinal; out Code: Integer); - -var - x: double; begin - Code:=0; - x:=Number(S); - if isNaN(x) or (X<>Int(X)) then - Code:=1 - else if (x<0) or (x>MaxCardinal) then - Code:=2 - else - C:=trunc(x); + C:=valint(S,low(C),high(C),Code); end; procedure val(const S: String; out B: Byte; out Code: Integer); - -var - x: double; begin - Code:=0; - x:=Number(S); - if isNaN(x) or (X<>Int(X)) then - Code:=1 - else if (x<0) or (x>MaxByte) then - Code:=2 - else - B:=Trunc(x); + B:=valint(S,low(B),high(B),Code); end; - procedure val(const S: String; out W: word; out Code: Integer); - -var - x: double; begin - Code:=0; - x:=Number(S); - if isNaN(x) then - Code:=1 - else if (x<0) or (x>MaxWord) then - Code:=2 - else - W:=Trunc(x); + W:=valint(S,low(W),high(W),Code); end; procedure val(const S : String; out I : integer; out Code : Integer); -var - x: double; begin - Code:=0; - x:=Number(S); - if isNaN(x) then - Code:=1 - else if x>MaxInt then - Code:=2 - else - I:=Trunc(x); + I:=valint(S,low(I),high(I),Code); end; procedure val(const S : String; out d : double; out Code : Integer); - Var x: double; begin