hedgewars/uUtils.pas
changeset 13826 94d0d1ab7a0e
parent 13317 092adcf707c5
child 13882 8c702a4839ec
--- a/hedgewars/uUtils.pas	Tue Oct 02 21:26:25 2018 +0200
+++ b/hedgewars/uUtils.pas	Tue Oct 02 21:51:27 2018 +0200
@@ -50,6 +50,7 @@
 
 function  IntToStr(n: LongInt): shortstring;
 function  StrToInt(s: shortstring): LongInt;
+function  StrToInt(s: shortstring; var success: boolean): LongInt;
 function  FloatToStr(n: hwFloat): shortstring;
 
 function  DxDy2Angle(const _dY, _dX: hwFloat): real; inline;
@@ -331,9 +332,22 @@
 str(n, IntToStr)
 end;
 
-function StrToInt(s: shortstring): LongInt;
+// Convert string to longint, with error checking.
+// Success will be set to false when conversion failed.
+// See documentation on Val procedure for syntax of s
+function StrToInt(s: shortstring; var success: boolean): LongInt;
+var Code: Word;
 begin
-val(s, StrToInt);
+val(s, StrToInt, Code);
+success:= Code = 0;
+end;
+
+// Convert string to longint, without error checking
+function StrToInt(s: shortstring): LongInt;
+var success: boolean; // ignored
+begin
+success:= true; // avoid compiler hint
+StrToInt:= StrToInt(s, success);
 end;
 
 function FloatToStr(n: hwFloat): shortstring;