Browse Source

rtl: added overload TryStrToFloat with type extended

mattias 6 years ago
parent
commit
5cdcf80eb7
1 changed files with 71 additions and 59 deletions
  1. 71 59
      packages/rtl/sysutils.pas

+ 71 - 59
packages/rtl/sysutils.pas

@@ -273,7 +273,8 @@ Type
 Function FloatToDecimal(Value : double; Precision, Decimals : integer) :  TFloatRec;
 Function FloatToDecimal(Value : double; Precision, Decimals : integer) :  TFloatRec;
 Function FloatToStr(Value: Double): String;
 Function FloatToStr(Value: Double): String;
 Function FloatToStrF(const Value : double; format: TFloatFormat; Precision, Digits: Integer): String;
 Function FloatToStrF(const Value : double; format: TFloatFormat; Precision, Digits: Integer): String;
-Function TryStrToFloat(const S : String; Out res : Double) : Boolean;
+Function TryStrToFloat(const S : String; Out res : Extended) : Boolean; overload;
+Function TryStrToFloat(const S : String; Out res : Double) : Boolean; overload;
 Function StrToFloatDef(const S : String; Const aDef : Double) : Double;
 Function StrToFloatDef(const S : String; Const aDef : Double) : Double;
 Function StrToFloat(const S : String) : Double;
 Function StrToFloat(const S : String) : Double;
 Function FormatFloat (Fmt : String; aValue : Double) : String;
 Function FormatFloat (Fmt : String; aValue : Double) : String;
@@ -660,7 +661,7 @@ begin
   Result:=Ch in CSet;
   Result:=Ch in CSet;
 end;
 end;
 
 
-Function CharInSet(Ch: Char;Const CSet : array of char) : Boolean;
+function CharInSet(Ch: Char; const CSet: array of char): Boolean;
 
 
 Var
 Var
   I : integer;
   I : integer;
@@ -706,7 +707,7 @@ begin
   Result:=str(Value);
   Result:=str(Value);
 end;
 end;
 
 
-Function FloatToDecimal(Value : double; Precision, Decimals : integer) :  TFloatRec;
+function FloatToDecimal(Value: double; Precision, Decimals: integer): TFloatRec;
 
 
 Const
 Const
   Rounds = '123456789:';
   Rounds = '123456789:';
@@ -853,7 +854,12 @@ begin
   Result:=FloatToStrF(Value,ffGeneral,15,0);
   Result:=FloatToStrF(Value,ffGeneral,15,0);
 end;
 end;
 
 
-Function TryStrToFloat(const S : String; Out res : Double) : Boolean;
+function TryStrToFloat(const S: String; out res: Extended): Boolean;
+begin
+  Result:=TryStrToFloat(S,double(res));
+end;
+
+function TryStrToFloat(const S: String; out res: Double): Boolean;
 
 
 Var
 Var
   J : JSValue;
   J : JSValue;
@@ -872,14 +878,13 @@ begin
     Res:=Double(J);
     Res:=Double(J);
 end;
 end;
 
 
-Function StrToFloatDef(const S : String; Const aDef : Double) : Double;
-
+function StrToFloatDef(const S: String; const aDef: Double): Double;
 begin
 begin
   if not TryStrToFloat(S,Result) then
   if not TryStrToFloat(S,Result) then
     Result:=aDef;
     Result:=aDef;
 end;
 end;
 
 
-Function StrToFloat(const S : String) : Double;
+function StrToFloat(const S: String): Double;
 begin
 begin
   if not TryStrToFloat(S,Result) then
   if not TryStrToFloat(S,Result) then
     Raise EConvertError.CreateFmt(SErrInvalidFloat,[S]);
     Raise EConvertError.CreateFmt(SErrInvalidFloat,[S]);
@@ -1722,7 +1727,8 @@ Begin
      end;
      end;
 end;
 end;
 
 
-Function FloatToStrF(const Value : double; format: TFloatFormat; Precision, Digits: Integer): String;
+function FloatToStrF(const Value: double; format: TFloatFormat; Precision,
+  Digits: Integer): String;
 
 
 Var
 Var
   DS: string;
   DS: string;
@@ -1745,7 +1751,7 @@ Begin
     RemoveLeadingNegativeSign(Result,DS);
     RemoveLeadingNegativeSign(Result,DS);
 end;
 end;
 
 
-function Format (const Fmt: String; const Args: array of jsvalue): String;
+function Format(const Fmt: String; const Args: array of JSValue): String;
 
 
 Var ChPos,OldPos,ArgPos,DoArg,Len : SizeInt;
 Var ChPos,OldPos,ArgPos,DoArg,Len : SizeInt;
     Hs,ToAdd : String;
     Hs,ToAdd : String;
@@ -2132,7 +2138,8 @@ end;
 Const
 Const
   RESpecials = '([\[\]\(\)\\\.\*])';
   RESpecials = '([\[\]\(\)\\\.\*])';
 
 
-Function StringReplace(aOriginal, aSearch, aReplace : string; Flags : TStringReplaceFlags) : String;
+function StringReplace(aOriginal, aSearch, aReplace: string;
+  Flags: TStringReplaceFlags): String;
 
 
 Var
 Var
   REFlags : String;
   REFlags : String;
@@ -2148,7 +2155,7 @@ begin
   Result:=TJSString(aOriginal).replace(TJSRegexp.new(REString,REFlags),aReplace);
   Result:=TJSString(aOriginal).replace(TJSRegexp.new(REString,REFlags),aReplace);
 end;
 end;
 
 
-Function QuoteString(aOriginal : String; AQuote : Char) : String;
+function QuoteString(aOriginal: String; AQuote: Char): String;
 
 
 begin
 begin
   Result:=AQuote+StringReplace(aOriginal,aQuote,aQuote+aQuote,[rfReplaceAll])+AQuote;
   Result:=AQuote+StringReplace(aOriginal,aQuote,aQuote+aQuote,[rfReplaceAll])+AQuote;
@@ -2237,7 +2244,8 @@ begin
   Result:=Res;
   Result:=Res;
 end;
 end;
 
 
-function WrapText(const Line, BreakStr: string; const BreakChars: Array of char;  MaxCol: Integer): string;
+function WrapText(const Line, BreakStr: string;
+  const BreakChars: array of char; MaxCol: Integer): string;
 
 
 const
 const
   Quotes = ['''', '"'];
   Quotes = ['''', '"'];
@@ -2346,7 +2354,7 @@ begin
     Result:=0;
     Result:=0;
 end;
 end;
 
 
-Function DateTimeToJSDate(aDateTime : TDateTime) : TJSDate;
+function DateTimeToJSDate(aDateTime: TDateTime): TJSDate;
 
 
 Var
 Var
   Y,M,D,h,n,s,z : Word;
   Y,M,D,h,n,s,z : Word;
@@ -2357,7 +2365,7 @@ begin
   Result:=TJSDate.New(Y,M,D,h,n,s,z);
   Result:=TJSDate.New(Y,M,D,h,n,s,z);
 end;
 end;
 
 
-Function JSDatetoDateTime(ADate: TJSDate) : TDateTime;
+function JSDateToDateTime(aDate: TJSDate): TDateTime;
 
 
 begin
 begin
   Result:=EncodeDate(ADate.FullYear,ADate.Month+1,ADate.Date) +
   Result:=EncodeDate(ADate.FullYear,ADate.Month+1,ADate.Date) +
@@ -2375,7 +2383,7 @@ begin
     Result := trunc(Date) + Abs(frac(Time));
     Result := trunc(Date) + Abs(frac(Time));
 end;
 end;
 
 
-Function TryEncodeDate(Year,Month,Day : Word; Out Date : TDateTime) : Boolean;
+function TryEncodeDate(Year, Month, Day: Word; out Date: TDateTime): Boolean;
 
 
 var
 var
   c, ya: LongWord;
   c, ya: LongWord;
@@ -2401,7 +2409,8 @@ begin
    end
    end
 end;
 end;
 
 
-function TryEncodeTime(Hour, Min, Sec, MSec:word; Out Time : TDateTime) : boolean;
+function TryEncodeTime(Hour, Min, Sec, MSec: Word; out Time: TDateTime
+  ): Boolean;
 
 
 begin
 begin
   Result:=(Hour<24) and (Min<60) and (Sec<60) and (MSec<1000);
   Result:=(Hour<24) and (Min<60) and (Sec<60) and (MSec<1000);
@@ -3033,7 +3042,7 @@ begin
     ErrorMsg:=Format(SErrInvalidTimeFormat,[S]);
     ErrorMsg:=Format(SErrInvalidTimeFormat,[S]);
 end ;
 end ;
 
 
-function StrToTime(const s: String; separator : char): TDateTime;
+function StrToTime(const S: String; separator: char): TDateTime;
 
 
 Var
 Var
   Msg : String;
   Msg : String;
@@ -3044,7 +3053,7 @@ begin
     Raise EConvertError.Create(Msg);
     Raise EConvertError.Create(Msg);
 end;
 end;
 
 
-function StrToTime(const s: String): TDateTime;
+function StrToTime(const S: String): TDateTime;
 begin
 begin
    result:= StrToTime(s, TimeSeparator);
    result:= StrToTime(s, TimeSeparator);
 end;
 end;
@@ -3126,7 +3135,7 @@ begin
     end;
     end;
 end;
 end;
 
 
-function StrToDateTime(const s: String): TDateTime;
+function StrToDateTime(const S: String): TDateTime;
 
 
 var
 var
   TimeStr, DateStr: String;
   TimeStr, DateStr: String;
@@ -3144,7 +3153,8 @@ begin
   end;
   end;
 end;
 end;
 
 
-Function FormatDateTime(const FormatStr: string; const DateTime: TDateTime) : String;
+function FormatDateTime(const FormatStr: string; const DateTime: TDateTime
+  ): string;
 
 
   procedure StoreStr(APos,Len: Integer);
   procedure StoreStr(APos,Len: Integer);
   begin
   begin
@@ -3511,7 +3521,7 @@ begin
   DateTime:=tmp;
   DateTime:=tmp;
 end;
 end;
 
 
-Function FloatToDateTime (Const Value : Extended) : TDateTime;
+function FloatToDateTime(const Value: Extended): TDateTime;
 begin
 begin
   If (Value<MinDateTime) or (Value>MaxDateTime) then
   If (Value<MinDateTime) or (Value>MaxDateTime) then
     Raise EConvertError.CreateFmt (SInvalidDateTime,[FloatToStr(Value)]);
     Raise EConvertError.CreateFmt (SInvalidDateTime,[FloatToStr(Value)]);
@@ -3604,14 +3614,13 @@ begin
      and (TObject(Obj).InheritsFrom(AClass));
      and (TObject(Obj).InheritsFrom(AClass));
 end;
 end;
 
 
-function Supports(const Instance: IInterface; const IID: TGUID; out Intf
+function Supports(const Instance: IInterface; const IID: TGuid; out Intf
   ): Boolean;
   ): Boolean;
 begin
 begin
   Result:=(Instance<>nil) and (Instance.QueryInterface(IID,Intf)=S_OK);
   Result:=(Instance<>nil) and (Instance.QueryInterface(IID,Intf)=S_OK);
 end;
 end;
 
 
-function Supports(const Instance: TObject; const IID: TGUID; out Intf
-  ): Boolean;
+function Supports(const Instance: TObject; const IID: TGuid; out Intf): Boolean;
 begin
 begin
   Result:=(Instance<>nil) and Instance.GetInterface(IID,Intf);
   Result:=(Instance<>nil) and Instance.GetInterface(IID,Intf);
 end;
 end;
@@ -3629,14 +3638,14 @@ begin
   Result:=Supports(Instance,AClass,Temp);
   Result:=Supports(Instance,AClass,Temp);
 end;
 end;
 
 
-function Supports(const Instance: IInterface; const IID: TGUID): Boolean;
+function Supports(const Instance: IInterface; const IID: TGuid): Boolean;
 var
 var
   Temp: IInterface;
   Temp: IInterface;
 begin
 begin
   Result:=Supports(Instance,IID,Temp);
   Result:=Supports(Instance,IID,Temp);
 end;
 end;
 
 
-function Supports(const Instance: TObject; const IID: TGUID): Boolean;
+function Supports(const Instance: TObject; const IID: TGuid): Boolean;
 var
 var
   Temp: TJSObject;
   Temp: TJSObject;
 begin
 begin
@@ -3656,7 +3665,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-function Supports(const AClass: TClass; const IID: TGUID): Boolean;
+function Supports(const AClass: TClass; const IID: TGuid): Boolean;
 var
 var
   maps: JSValue;
   maps: JSValue;
 begin
 begin
@@ -3678,7 +3687,7 @@ begin
   Result:=false;
   Result:=false;
 end;
 end;
 
 
-function TryStringToGUID(const s: string; out Guid: TGUID): Boolean;
+function TryStringToGUID(const s: string; out Guid: TGuid): Boolean;
 var
 var
   re: TJSRegexp;
   re: TJSRegexp;
 begin
 begin
@@ -3696,18 +3705,18 @@ begin
   Result:=true;
   Result:=true;
 end;
 end;
 
 
-function StringToGUID(const S: string): TGUID;
+function StringToGUID(const S: string): TGuid;
 begin
 begin
   if not TryStringToGUID(S, Result) then
   if not TryStringToGUID(S, Result) then
     raise EConvertError.CreateFmt(SInvalidGUID, [S]);
     raise EConvertError.CreateFmt(SInvalidGUID, [S]);
 end;
 end;
 
 
-function GUIDToString(const guid: TGUID): string;
+function GUIDToString(const guid: TGuid): string;
 begin
 begin
   Result:=System.GUIDToString(guid);
   Result:=System.GUIDToString(guid);
 end;
 end;
 
 
-function IsEqualGUID(const guid1, guid2: TGUID): Boolean;
+function IsEqualGUID(const guid1, guid2: TGuid): Boolean;
 var
 var
   i: integer;
   i: integer;
 begin
 begin
@@ -3717,7 +3726,7 @@ begin
   Result:=true;
   Result:=true;
 end;
 end;
 
 
-function GuidCase(const guid: TGUID; const List: array of TGuid): Integer;
+function GuidCase(const guid: TGuid; const List: array of TGuid): Integer;
 begin
 begin
   for Result := High(List) downto 0 do
   for Result := High(List) downto 0 do
     if IsEqualGUID(guid, List[Result]) then
     if IsEqualGUID(guid, List[Result]) then
@@ -3725,7 +3734,7 @@ begin
   Result := -1;
   Result := -1;
 end;
 end;
 
 
-Function CreateGUID(out GUID : TGUID) : Integer;
+function CreateGUID(out GUID: TGUID): Integer;
 
 
   Function R(B: Integer) : NativeInt;
   Function R(B: Integer) : NativeInt;
 
 
@@ -3756,7 +3765,7 @@ end;
   Integer/Ordinal related
   Integer/Ordinal related
   ---------------------------------------------------------------------}
   ---------------------------------------------------------------------}
 
 
-Function TryStrToInt(const S : String; Out res : Integer) : Boolean;
+function TryStrToInt(const S: String; out res: Integer): Boolean;
 
 
 Var
 Var
   NI : NativeInt;
   NI : NativeInt;
@@ -3767,7 +3776,7 @@ begin
     res:=NI;
     res:=NI;
 end;
 end;
 
 
-Function TryStrToInt(const S : String; Out res : NativeInt) : Boolean;
+function TryStrToInt(const S: String; out res: NativeInt): Boolean;
 
 
 Var
 Var
   Radix : Integer = 10;
   Radix : Integer = 10;
@@ -3789,7 +3798,7 @@ begin
     res:=NativeInt(J);
     res:=NativeInt(J);
 end;
 end;
 
 
-Function StrToIntDef(const S : String; Const aDef : Integer) : Integer;
+function StrToIntDef(const S: String; const aDef: Integer): Integer;
 
 
 Var
 Var
   R : NativeInt;
   R : NativeInt;
@@ -3801,7 +3810,7 @@ begin
     Result:=aDef;
     Result:=aDef;
 end;
 end;
 
 
-Function StrToIntDef(const S : String; Const aDef : NativeInt) : NativeInt;
+function StrToIntDef(const S: String; const aDef: NativeInt): NativeInt;
 
 
 Var
 Var
   R : NativeInt;
   R : NativeInt;
@@ -3813,7 +3822,7 @@ begin
     Result:=aDef;
     Result:=aDef;
 end;
 end;
 
 
-Function StrToInt(const S : String) : Integer;
+function StrToInt(const S: String): Integer;
 
 
 Var
 Var
   R : NativeInt;
   R : NativeInt;
@@ -3824,14 +3833,14 @@ begin
   Result:=R;
   Result:=R;
 end;
 end;
 
 
-Function StrToNativeInt(const S : String) : NativeInt;
+function StrToNativeInt(const S: String): NativeInt;
 
 
 begin
 begin
   if not TryStrToInt(S,Result) then
   if not TryStrToInt(S,Result) then
     Raise EConvertError.CreateFmt(SErrInvalidInteger,[S]);
     Raise EConvertError.CreateFmt(SErrInvalidInteger,[S]);
 end;
 end;
 
 
-Function StrToInt64(const S : String) : NativeLargeInt;
+function StrToInt64(const S: String): NativeLargeInt;
 
 
 Var
 Var
   N : NativeInt;
   N : NativeInt;
@@ -3842,7 +3851,7 @@ begin
   Result:=N;
   Result:=N;
 end;
 end;
 
 
-Function TryStrToInt64(const S : String; Out res : NativeLargeInt) : Boolean;
+function TryStrToInt64(const S: String; out res: NativeLargeInt): Boolean;
 
 
 Var
 Var
   R : nativeint;
   R : nativeint;
@@ -3853,7 +3862,8 @@ begin
     Res:=R;
     Res:=R;
 end;
 end;
 
 
-Function StrToInt64Def(const S : String; ADefault : NativeLargeInt) : NativeLargeInt;
+function StrToInt64Def(const S: String; ADefault: NativeLargeInt
+  ): NativeLargeInt;
 
 
 
 
 begin
 begin
@@ -3861,7 +3871,7 @@ begin
     Result:=ADefault;
     Result:=ADefault;
 end;
 end;
 
 
-Function StrToQWord(const S : String) : NativeLargeUInt;
+function StrToQWord(const S: String): NativeLargeUInt;
 
 
 Var
 Var
   N : NativeInt;
   N : NativeInt;
@@ -3872,7 +3882,7 @@ begin
   Result:=N;
   Result:=N;
 end;
 end;
 
 
-Function TryStrToQWord(const S : String; Out res : NativeLargeUInt) : Boolean;
+function TryStrToQWord(const S: String; out res: NativeLargeUInt): Boolean;
 
 
 Var
 Var
   R : nativeint;
   R : nativeint;
@@ -3883,7 +3893,8 @@ begin
     Res:=R;
     Res:=R;
 end;
 end;
 
 
-Function StrToQWordDef(const S : String; ADefault : NativeLargeUInt) : NativeLargeUInt;
+function StrToQWordDef(const S: String; ADefault: NativeLargeUInt
+  ): NativeLargeUInt;
 
 
 begin
 begin
   if Not TryStrToQword(S,Result) then
   if Not TryStrToQword(S,Result) then
@@ -3891,7 +3902,7 @@ begin
 end;
 end;
 
 
 
 
-Function StrToUInt64(const S : String) : NativeLargeUInt;
+function StrToUInt64(const S: String): NativeLargeUInt;
 
 
 Var
 Var
   N : NativeInt;
   N : NativeInt;
@@ -3902,7 +3913,7 @@ begin
   Result:=N;
   Result:=N;
 end;
 end;
 
 
-Function TryStrToUInt64(const S : String; Out res : NativeLargeUInt) : Boolean;
+function TryStrToUInt64(const S: String; out res: NativeLargeUInt): Boolean;
 
 
 Var
 Var
   R : nativeint;
   R : nativeint;
@@ -3913,7 +3924,8 @@ begin
     Res:=R;
     Res:=R;
 end;
 end;
 
 
-Function StrToUInt64Def(const S : String; ADefault : NativeLargeUInt) : NativeLargeUInt;
+function StrToUInt64Def(const S: String; ADefault: NativeLargeUInt
+  ): NativeLargeUInt;
 
 
 
 
 begin
 begin
@@ -3921,7 +3933,7 @@ begin
     Result:=ADefault;
     Result:=ADefault;
 end;
 end;
 
 
-Function TryStrToDWord(const S : String; Out res : DWord) : Boolean;
+function TryStrToDWord(const S: String; out res: DWord): Boolean;
 
 
 Var
 Var
   R : nativeint;
   R : nativeint;
@@ -3932,7 +3944,7 @@ begin
     Res:=R;
     Res:=R;
 end;
 end;
 
 
-Function StrToDWord(const S : String) : DWord;
+function StrToDWord(const S: String): DWord;
 
 
 begin
 begin
   if not TryStrToDWord(S,Result) then
   if not TryStrToDWord(S,Result) then
@@ -3940,7 +3952,7 @@ begin
 end;
 end;
 
 
 
 
-Function StrToDWordDef(const S : String; ADefault : DWord) : DWord;
+function StrToDWordDef(const S: String; ADefault: DWord): DWord;
 
 
 begin
 begin
   if Not TryStrToDWord(S,Result) then
   if Not TryStrToDWord(S,Result) then
@@ -4268,7 +4280,7 @@ begin
     Result := '';
     Result := '';
 end;
 end;
 
 
-function ExtractRelativepath (Const BaseName,DestName : PathStr): PathStr;
+function ExtractRelativepath(const BaseName, DestName: PathStr): PathStr;
 
 
 Var
 Var
   OneLevelBack,Source, Dest   : PathStr;
   OneLevelBack,Source, Dest   : PathStr;
@@ -4303,7 +4315,7 @@ begin
   Result:=Result+ExtractFileName(DestName);
   Result:=Result+ExtractFileName(DestName);
 end;
 end;
 
 
-Function SetDirSeparators (Const FileName : PathStr) : PathStr;
+function SetDirSeparators(const FileName: PathStr): PathStr;
 
 
 Var
 Var
   I : integer;
   I : integer;
@@ -4315,7 +4327,7 @@ begin
       Result[i]:=PathDelim;
       Result[i]:=PathDelim;
 end;
 end;
 
 
-Function GetDirs (DirName : PathStr) : TPathStrArray;
+function GetDirs(DirName: PathStr): TPathStrArray;
 
 
 Var
 Var
   I,J,L : Longint;
   I,J,L : Longint;
@@ -4343,7 +4355,7 @@ begin
   SetLength(Result,L);
   SetLength(Result,L);
 end;
 end;
 
 
-function IncludeTrailingPathDelimiter(Const Path : PathStr) : PathStr;
+function IncludeTrailingPathDelimiter(const Path: PathStr): PathStr;
 
 
 Var
 Var
   l : Integer;
   l : Integer;
@@ -4355,7 +4367,7 @@ begin
     Result:=Result+PathDelim;
     Result:=Result+PathDelim;
 end;
 end;
 
 
-function ExcludeTrailingPathDelimiter(Const Path: PathStr): PathStr;
+function ExcludeTrailingPathDelimiter(const Path: PathStr): PathStr;
 
 
 Var
 Var
   L : Integer;
   L : Integer;
@@ -4367,7 +4379,7 @@ begin
   Result:=Copy(Path,1,L);
   Result:=Copy(Path,1,L);
 end;
 end;
 
 
-function IncludeLeadingPathDelimiter(Const Path : PathStr) : PathStr;
+function IncludeLeadingPathDelimiter(const Path: PathStr): PathStr;
 
 
 Var
 Var
   l : Integer;
   l : Integer;
@@ -4379,7 +4391,7 @@ begin
     Result:=PathDelim+Result;
     Result:=PathDelim+Result;
 end;
 end;
 
 
-function ExcludeLeadingPathDelimiter(Const Path: PathStr): PathStr;
+function ExcludeLeadingPathDelimiter(const Path: PathStr): PathStr;
 
 
 Var
 Var
   L : Integer;
   L : Integer;
@@ -4391,7 +4403,7 @@ begin
     Delete(Result,1,1);
     Delete(Result,1,1);
 end;
 end;
 
 
-function IsPathDelimiter(Const Path: PathStr; Index: Integer): Boolean;
+function IsPathDelimiter(const Path: PathStr; Index: Integer): Boolean;
 
 
 begin
 begin
   Result:=(Index>0) and (Index<=Length(Path)) and CharInSet(Path[Index],AllowDirectorySeparators);
   Result:=(Index>0) and (Index<=Length(Path)) and CharInSet(Path[Index],AllowDirectorySeparators);