From beef11fba94ced6ee33534c14d4374aff525e5da Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Sun, 3 Nov 2024 17:21:23 +0100 Subject: [PATCH] Added ToFree --- sources/MVCFramework.pas | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sources/MVCFramework.pas b/sources/MVCFramework.pas index db177f59..d4a3996d 100644 --- a/sources/MVCFramework.pas +++ b/sources/MVCFramework.pas @@ -893,9 +893,10 @@ type TMVCController = class(TMVCRenderer) private - FViewModel: TMVCViewDataObject; + fViewModel: TMVCViewDataObject; fPageHeaders: TArray; fPageFooters: TArray; + fFreeList: TObjectList; function GetSession: TMVCWebSession; function GetViewData(const aModelName: string): TValue; procedure SetViewData(const aModelName: string; const Value: TValue); @@ -905,6 +906,11 @@ type procedure MVCControllerAfterCreate; virtual; procedure MVCControllerBeforeDestroy; virtual; + /// + /// After action execution frees all the objects added. Works only with functional actions. + /// + function ToFree(aObject: T): T; overload; + procedure OnBeforeAction(AContext: TWebContext; const AActionName: string; var AHandled: Boolean); virtual; procedure OnAfterAction(AContext: TWebContext; const AActionName: string); virtual; @@ -2953,6 +2959,7 @@ begin end; end; finally + lSelectedController.fFreeList.Free; lSelectedController.OnAfterAction(lContext, lRouterMethodToCallName); end; end; @@ -4193,6 +4200,16 @@ begin Result := GetSHA1HashFromString(Data); end; +function TMVCController.ToFree(aObject: T): T; +begin + if not Assigned(fFreeList) then + begin + fFreeList := TObjectList.Create(True); + end; + fFreeList.Add(aObject); + Result := aObject; +end; + function TMVCController.GetIfMatch: String; begin Result := Context.Request.GetHeader('If-Match');