浏览代码

* Bug ID #29779, add DWord versions of StrToInt

git-svn-id: trunk@33153 -
michael 9 年之前
父节点
当前提交
5568ee5513
共有 2 个文件被更改,包括 28 次插入2 次删除
  1. 23 0
      rtl/objpas/sysutils/sysstr.inc
  2. 5 2
      rtl/objpas/sysutils/sysstrh.inc

+ 23 - 0
rtl/objpas/sysutils/sysstr.inc

@@ -845,6 +845,19 @@ begin
   if Error <> 0 then raise EConvertError.createfmt(SInvalidInteger,[S]);
 end;
 
+function StrToDWord(const s: string): DWord;
+var Error: word;
+begin
+  Val(S, result, Error);
+  if Error <> 0 then raise EConvertError.createfmt(SInvalidInteger,[S]);
+end;
+
+function TryStrToDWord(const s: string; Out D: DWord): boolean;
+var Error : word;
+begin
+  Val(s, D, Error);
+  TryStrToDWord:=Error=0
+end;
 
 function TryStrToQWord(const s: string; Out Q: QWord): boolean;
 var Error : word;
@@ -863,6 +876,16 @@ begin
   if Error <> 0 then result := Default;
 end ;
 
+{   StrToDWordDef converts the string S to an DWord value,
+    Default is returned in case S does not represent a valid DWord value  }
+
+function StrToDWordDef(const S: string; Default: DWord): DWord;
+var Error: word;
+begin
+  Val(S, result, Error);
+  if Error <> 0 then result := Default;
+end;
+
 {   StrToInt64Def converts the string S to an int64 value,
     Default is returned in case S does not represent a valid int64 value  }
 

+ 5 - 2
rtl/objpas/sysutils/sysstrh.inc

@@ -111,12 +111,15 @@ function IntToHex(Value: Longint; Digits: integer): string;
 function IntToHex(Value: Int64; Digits: integer): string;
 function IntToHex(Value: QWord; Digits: integer): string;
 function StrToInt(const s: string): Longint;
-function TryStrToInt(const s: string; Out i : Longint) : boolean;
+function StrToDWord(const s: string): DWord;
 function StrToInt64(const s: string): int64;
-function TryStrToInt64(const s: string; Out i : int64) : boolean;
 function StrToQWord(const s: string): QWord;
+function TryStrToInt(const s: string; Out i : Longint) : boolean;
+function TryStrToDWord(const s: string; Out D : DWord) : boolean;
+function TryStrToInt64(const s: string; Out i : int64) : boolean;
 function TryStrToQWord(const s: string; Out Q : QWord) : boolean;
 function StrToIntDef(const S: string; Default: Longint): Longint;
+function StrToDWordDef(const S: string; Default: DWord): DWord;
 function StrToInt64Def(const S: string; Default: int64): int64;
 function StrToQWordDef(const S: string; Default: QWord): QWord;
 function LoadStr(Ident: integer): string;