* Fix bug #31176: (Try)StrToBool should accept localized floats

git-svn-id: trunk@35331 -
This commit is contained in:
michael 2017-01-25 21:23:07 +00:00
parent 27329429d9
commit b5fb706a65
2 changed files with 23 additions and 2 deletions

View File

@ -1909,7 +1909,13 @@ end;
function StrToBool(const S: string): Boolean;
begin
if not(TryStrToBool(S,Result)) then
if not(TryStrToBool(S,Result,DefaultFormatSettings)) then
Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
end;
function StrToBool(const S: string; const FormatSettings: TFormatSettings): Boolean;
begin
if not(TryStrToBool(S,Result,FormatSettings)) then
Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
end;
@ -1957,7 +1963,19 @@ begin
Result:=Default;
end;
function StrToBoolDef(const S: string; Default: Boolean; const FormatSettings: TFormatSettings): Boolean;
begin
if not(TryStrToBool(S,Result,FormatSettings)) then
Result:=Default;
end;
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
begin
Result:=TryStrToBool(S,Value,DefaultFormatSettings);
end;
function TryStrToBool(const S: string; out Value: Boolean; const FormatSettings: TFormatSettings): Boolean;
Var
Temp : String;
I : Longint;
@ -1971,7 +1989,7 @@ begin
Temp:=upcase(S);
Val(temp,D,code);
Result:=true;
If Code=0 then
If (Code=0) or TryStrToFloat(S,D,FormatSettings) then
{$ifdef FPUNONE}
Value:=(D<>0)
{$else}

View File

@ -223,10 +223,13 @@ Function FormatCurr(const Format: string; Value: Currency; Const FormatSettings:
{$endif}
function StrToBool(const S: string): Boolean;
function StrToBool(const S: string; Const FormatSettings: TFormatSettings): Boolean;
function BoolToStr(B: Boolean;UseBoolStrs:Boolean=False): string;
function BoolToStr(B: Boolean;const TrueS,FalseS:string): string; inline;
function StrToBoolDef(const S: string; Default: Boolean): Boolean;
function StrToBoolDef(const S: string; Default: Boolean; Const FormatSettings: TFormatSettings): Boolean;
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
function TryStrToBool(const S: string; out Value: Boolean; Const FormatSettings: TFormatSettings): Boolean;
function LastDelimiter(const Delimiters, S: string): SizeInt;
function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;