From c75eea7517b85df19d33e91caa07c58887b02ef4 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Tue, 5 Nov 2024 12:32:38 +0100 Subject: [PATCH] Updated TemplatePro --- ...VCFramework.View.Renderers.TemplatePro.pas | 4 +- sources/TemplatePro.pas | 64 ++++++++++++++----- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/sources/MVCFramework.View.Renderers.TemplatePro.pas b/sources/MVCFramework.View.Renderers.TemplatePro.pas index 69ab30dd..f8377187 100644 --- a/sources/MVCFramework.View.Renderers.TemplatePro.pas +++ b/sources/MVCFramework.View.Renderers.TemplatePro.pas @@ -57,12 +57,12 @@ var begin if not aValue.IsObject then begin - Result := False; + Exit(False); end; if Length(aParameters) <> 0 then begin - Result := '(Error: Expected 0 params, got ' + Length(aParameters).ToString + ')'; + raise EMVCSSVException.Create('Expected 0 params, got ' + Length(aParameters).ToString); end; if aValue.AsObject is TDataSet then diff --git a/sources/TemplatePro.pas b/sources/TemplatePro.pas index e8e8f5df..508e0970 100644 --- a/sources/TemplatePro.pas +++ b/sources/TemplatePro.pas @@ -523,6 +523,17 @@ function TTProCompiledTemplate.GetTValueVarAsString(const Value: TValue; const V var lIsObject: Boolean; lAsObject: TObject; + lNullableInt32: NullableInt32; + lNullableUInt32: NullableUInt32; + lNullableInt16: NullableInt16; + lNullableUInt16: NullableUInt16; + lNullableInt64: NullableInt64; + lNullableUInt64: NullableUInt64; + lNullableCurrency: NullableCurrency; + lNullableBoolean: NullableBoolean; + lNullableTDate: NullableTDate; + lNullableTTime: NullableTTime; + lNullableTDateTime: NullableTDateTime; begin if Value.IsEmpty then begin @@ -550,53 +561,76 @@ begin begin if Value.TypeInfo.Kind = tkRecord then begin + Result := ''; if Value.TypeInfo = TypeInfo(NullableInt32) then begin - Result := Value.AsType.Value.ToString; + lNullableInt32 := Value.AsType; + if lNullableInt32.HasValue then + Result := lNullableInt32.Value.ToString end else if Value.TypeInfo = TypeInfo(NullableUInt32) then begin - Result := Value.AsType.Value.ToString; + lNullableUInt32 := Value.AsType; + if lNullableUInt32.HasValue then + Result := lNullableUInt32.Value.ToString end else if Value.TypeInfo = TypeInfo(NullableInt16) then begin - Result := Value.AsType.Value.ToString; + lNullableInt16 := Value.AsType; + if lNullableInt16.HasValue then + Result := lNullableInt16.Value.ToString end else if Value.TypeInfo = TypeInfo(NullableUInt16) then begin - Result := Value.AsType.Value.ToString; + lNullableUInt16 := Value.AsType; + if lNullableUInt16.HasValue then + Result := lNullableUInt16.Value.ToString end else if Value.TypeInfo = TypeInfo(NullableInt64) then begin - Result := Value.AsType.Value.ToString; + lNullableInt64 := Value.AsType; + if lNullableInt64.HasValue then + Result := lNullableInt64.Value.ToString end - else if Value.TypeInfo = TypeInfo(NullableInt64) then + else if Value.TypeInfo = TypeInfo(NullableUInt64) then begin - Result := Value.AsType.Value.ToString; + lNullableUInt64 := Value.AsType; + if lNullableUInt64.HasValue then + Result := lNullableUInt64.Value.ToString end else if Value.TypeInfo = TypeInfo(NullableString) then begin - Result := Value.AsType.Value; + Result := Value.AsType.ValueOrDefault; end else if Value.TypeInfo = TypeInfo(NullableCurrency) then begin - Result := Value.AsType.Value.ToString; + lNullableCurrency := Value.AsType; + if lNullableCurrency.HasValue then + Result := FloatToStr(lNullableCurrency.Value, fLocaleFormatSettings); end else if Value.TypeInfo = TypeInfo(NullableBoolean) then begin - Result := Value.AsType.Value.ToString; + lNullableBoolean := Value.AsType; + if lNullableBoolean.HasValue then + Result := BoolToStr(lNullableBoolean.Value, True); end else if Value.TypeInfo = TypeInfo(NullableTDate) then begin - Result := DateToISO8601(Value.AsType.Value); + lNullableTDate := Value.AsType; + if lNullableTDate.HasValue then + Result := DateToISO8601(lNullableTDate.Value); end else if Value.TypeInfo = TypeInfo(NullableTTime) then begin - Result := DateToISO8601(Value.AsType.Value); + lNullableTTime := Value.AsType; + if lNullableTTime.HasValue then + Result := DateToISO8601(lNullableTTime.Value); end else if Value.TypeInfo = TypeInfo(NullableTDateTime) then begin - Result := DateToISO8601(Value.AsType.Value); + lNullableTDateTime := Value.AsType; + if lNullableTDateTime.HasValue then + Result := DateToISO8601(lNullableTDateTime.Value); end else begin @@ -3299,10 +3333,10 @@ var begin ARttiType := GlContext.GetType(AObject.ClassType); if not Assigned(ARttiType) then - raise Exception.CreateFmt('Cannot get RTTI for type [%s]', [ARttiType.ToString]); + raise Exception.CreateFmt('Unknown type [%s]', [ARttiType.ToString]); Prop := ARttiType.GetProperty(APropertyName); if not Assigned(Prop) then - raise Exception.CreateFmt('Cannot get RTTI for property [%s.%s]', [ARttiType.ToString, APropertyName]); + raise Exception.CreateFmt('Unknown property [%s.%s]', [ARttiType.ToString, APropertyName]); if Prop.IsReadable then Result := Prop.GetValue(AObject) else