From 9e1965237ba83c2747356d394e2d9c5c147480b8 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Tue, 17 Dec 2024 11:37:26 +0100 Subject: [PATCH] https://github.com/danieleteti/delphimvcframework/issues/798 --- sources/TemplatePro.pas | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/sources/TemplatePro.pas b/sources/TemplatePro.pas index 836ad68f..d7c631ab 100644 --- a/sources/TemplatePro.pas +++ b/sources/TemplatePro.pas @@ -30,9 +30,9 @@ interface System.Classes, System.SysUtils, System.TypInfo, - Data.DB, System.DateUtils, - System.RTTI; + System.RTTI, + Data.DB; const TEMPLATEPRO_VERSION = '0.7.2'; @@ -294,7 +294,7 @@ implementation uses System.StrUtils, System.IOUtils, System.NetEncoding, System.Math, System.Character, - JsonDataObjects, MVCFramework.Nullables; + JsonDataObjects, MVCFramework.Nullables, Data.FmtBCD; const Sign = ['-', '+']; @@ -536,18 +536,22 @@ function TTProCompiledTemplate.GetDataSetFieldAsTValue(const aDataSet: TDataSet; Result := lField.AsLargeInt; ftFloat: Result := lField.AsFloat; + ftSingle: + Result := lField.AsSingle; ftCurrency: Result := lField.AsCurrency; ftString, ftWideString, ftMemo, ftWideMemo: Result := lField.AsWideString; ftDate: Result := TDate(Trunc(lField.AsDateTime)); - ftDateTime: + ftDateTime, ftTimeStamp: Result := lField.AsDateTime; ftTime: Result := lField.AsDateTime; ftBoolean: Result := lField.AsBoolean; + ftFMTBcd: + Result := TValue.From(lField.AsBCD); else Error('Invalid data type for field "%s": %s', [FieldName, TRttiEnumerationType.GetName(lField.DataType)]); end; @@ -730,7 +734,7 @@ function TTProCompiledTemplate.GetTValueVarAsString(const Value: PValue; const V end else begin - if Value.TypeInfo.Kind = tkRecord then + if (Value.TypeInfo.Kind = tkRecord) and (Value.TypeInfo <> TypeInfo(TBcd)) then begin Result := ''; if Value.TypeInfo = TypeInfo(NullableInt32) then @@ -836,6 +840,17 @@ function TTProCompiledTemplate.GetTValueVarAsString(const Value: PValue; const V end; tkEnumeration: Result := Value.ToString; + tkRecord: + begin + if Value.TypeInfo = TypeInfo(TBcd) then + begin + Result := BcdToStr(PBCD(Value.GetReferenceToRawData)^, fLocaleFormatSettings); + end + else + begin + raise ETProException.Create('Unsupported type for record variable "' + VarName + '"'); + end; + end else raise ETProException.Create('Unsupported type for variable "' + VarName + '"'); end;