From a4bad60e2c36b6e1702c69ec7556c10ac95c3659 Mon Sep 17 00:00:00 2001 From: jesus Date: Sat, 8 Sep 2018 06:30:49 +0000 Subject: [PATCH] LazReport: check for null in formatfloat function, issue #34213 git-svn-id: trunk@58906 - --- components/lazreport/source/lr_class.pas | 2 +- components/lazreport/source/lr_utils.pas | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/components/lazreport/source/lr_class.pas b/components/lazreport/source/lr_class.pas index ba3e718ec6..7822825096 100644 --- a/components/lazreport/source/lr_class.pas +++ b/components/lazreport/source/lr_class.pas @@ -12587,7 +12587,7 @@ begin 1: dk := dkCount; //Add('COUNT'); {1} 2: val := DayOf(frParser.Calc(p1)); //Add('DAYOF'); {2} 3: val := FormatDateTime(frParser.Calc(p1), frParser.Calc(p2)); //Add('FORMATDATETIME'); {3} - 4: val := FormatFloat(frParser.Calc(p1), frParser.Calc(p2)); //Add('FORMATFLOAT'); {4} + 4: val := FormatFloat(frParser.Calc(p1), lrVarToFloatDef(frParser.Calc(p2))); //Add('FORMATFLOAT'); {4} 5: val := FormatMaskText(frParser.Calc(p1) + ';0; ', frParser.Calc(p2)); //Add('FORMATTEXT'); {5} 6:begin //Add('INPUT'); {6} s1 := InputBox('', frParser.Calc(p1), frParser.Calc(p2)); diff --git a/components/lazreport/source/lr_utils.pas b/components/lazreport/source/lr_utils.pas index fc606dde2d..41e33dedad 100644 --- a/components/lazreport/source/lr_utils.pas +++ b/components/lazreport/source/lr_utils.pas @@ -15,7 +15,7 @@ interface {$I LR_Vers.inc} uses - SysUtils, Classes, strutils, Graphics, Controls, + SysUtils, Classes, strutils, Variants, Graphics, Controls, LR_DBRel, Forms, StdCtrls, ClipBrd, Menus, db, {$IFDEF WIN32} Windows, @@ -70,6 +70,7 @@ function lrExpandVariables(const S:string):string; procedure lrNormalizeLocaleFloats(DisableLocale: boolean); function lrConfigFolderName(ACreatePath: boolean): string; function lrCanReadName(Stream: TStream): boolean; +function lrVarToFloatDef(AValue:Variant; aDefault:Extended=0.0): Extended; procedure CanvasTextRectJustify(const Canvas:TCanvas; const ARect: TRect; X1, X2, Y: integer; const Text: string; @@ -955,6 +956,14 @@ begin end; end; +function lrVarToFloatDef(AValue: Variant; aDefault: Extended): Extended; +begin + if not VarIsNumeric(AValue) then + result := ADefault + else + result := AValue; +end; + function UTF8Desc(S: string; var Desc: string): Integer; // create Desc as an array with Desc[i] is the size of the UTF-8 codepoint var