Browse Source

* val takes care of empty string, patch from Petr Kristan

git-svn-id: trunk@10609 -
florian 17 years ago
parent
commit
347ae5a3bf
1 changed files with 9 additions and 3 deletions
  1. 9 3
      rtl/inc/sstrings.inc

+ 9 - 3
rtl/inc/sstrings.inc

@@ -765,12 +765,18 @@ Function InitVal(const s:shortstring;out negativ:boolean;out base:byte):ValSInt;
 var
 var
   Code : SizeInt;
   Code : SizeInt;
 begin
 begin
-{Skip Spaces and Tab}
   code:=1;
   code:=1;
+  negativ:=false;
+  base:=10;
+  if length(s)=0 then 
+    begin
+      InitVal:=code;
+      Exit;
+    end;
+{Skip Spaces and Tab}
   while (code<=length(s)) and (s[code] in [' ',#9]) do
   while (code<=length(s)) and (s[code] in [' ',#9]) do
    inc(code);
    inc(code);
 {Sign}
 {Sign}
-  negativ:=false;
   case s[code] of
   case s[code] of
    '-' : begin
    '-' : begin
            negativ:=true;
            negativ:=true;
@@ -779,7 +785,6 @@ begin
    '+' : inc(code);
    '+' : inc(code);
   end;
   end;
 {Base}
 {Base}
-  base:=10;
   if code<=length(s) then
   if code<=length(s) then
    begin
    begin
      case s[code] of
      case s[code] of
@@ -1388,3 +1393,4 @@ begin
     ShortCompareText := L1 - L2;
     ShortCompareText := L1 - L2;
 end;
 end;
 
 
+