(cherry picked from commit 1e74c418aed097b4f47c84f68b7e7207d56eaba4)
@@ -959,10 +959,14 @@ begin
end;
function TryStrToInt(const s: string; out i : Longint) : boolean;
-var Error : word;
+var
+ Error : word;
+ li : Int64;
begin
- Val(s, i, Error);
- TryStrToInt:=Error=0
+ Val(s, li, Error);
+ TryStrToInt:=(Error=0) and (li<=High(Longint)) and (li>=Low(Longint));
+ if TryStrToInt then
+ i:=li;
{ StrToInt converts the string S to an integer value,