|
@@ -5,8 +5,7 @@ unit Fresnel.App;
|
|
|
interface
|
|
|
|
|
|
uses
|
|
|
- Classes, SysUtils, CustApp, Fresnel.Events, Fresnel.Forms, Fresnel.WidgetSet,
|
|
|
- LazMethodList, LazLoggerBase;
|
|
|
+ Classes, SysUtils, CustApp, Fresnel.Events, Fresnel.Forms, Fresnel.WidgetSet;
|
|
|
|
|
|
type
|
|
|
TApplicationFlag = (
|
|
@@ -33,7 +32,6 @@ type
|
|
|
FOldExceptProc: TExceptProc;
|
|
|
procedure Activate(Data: Pointer);
|
|
|
procedure Deactivate(Data: Pointer);
|
|
|
- procedure QueuedReleaseComponents(Data: Pointer);
|
|
|
protected
|
|
|
protected
|
|
|
FFlags: TApplicationFlags;
|
|
@@ -52,7 +50,7 @@ type
|
|
|
procedure ReleaseComponent(aComponent : TComponent);
|
|
|
|
|
|
procedure ProcessAsyncCallQueue; virtual;
|
|
|
- procedure ReleaseComponents; virtual;
|
|
|
+
|
|
|
procedure SetCaptureExceptions(const AValue: Boolean); virtual;
|
|
|
procedure SetFlags(const AValue: TApplicationFlags); virtual;
|
|
|
public
|
|
@@ -80,6 +78,8 @@ var
|
|
|
|
|
|
implementation
|
|
|
|
|
|
+uses fresnel.classes;
|
|
|
+
|
|
|
var
|
|
|
HandlingException: Boolean = False;
|
|
|
HaltingProgram: Boolean = False;
|
|
@@ -87,7 +87,7 @@ var
|
|
|
procedure ExceptionOccurred(Sender: TObject; Addr: Pointer; FrameCount: Longint;
|
|
|
Frames: PPointer);
|
|
|
Begin
|
|
|
- DebugLn('[Fresnel.Forms] ExceptionOccurred ');
|
|
|
+ FLLog(etDebug,'[Fresnel.Forms] ExceptionOccurred ');
|
|
|
if HaltingProgram or HandlingException then Halt;
|
|
|
if Addr=nil then ;
|
|
|
if FrameCount=0 then ;
|
|
@@ -96,14 +96,9 @@ Begin
|
|
|
HandlingException:=true;
|
|
|
if Sender<>nil then
|
|
|
begin
|
|
|
- DebugLn(' Sender=',Sender.ClassName);
|
|
|
- if Sender is Exception then
|
|
|
- begin
|
|
|
- DebugLn(' Exception=',Exception(Sender).Message);
|
|
|
- DumpExceptionBackTrace();
|
|
|
- end;
|
|
|
+ FLLog(etDebug,' Sender='+Sender.Tostring);
|
|
|
end else
|
|
|
- DebugLn(' Sender=nil');
|
|
|
+ FLLog(etDebug,' Sender=nil');
|
|
|
if FresnelApplication<>nil then
|
|
|
FresnelApplication.HandleException(Sender);
|
|
|
HandlingException:=false;
|
|
@@ -186,11 +181,6 @@ begin
|
|
|
if Data=nil then ;
|
|
|
end;
|
|
|
|
|
|
-procedure TFresnelApplication.QueuedReleaseComponents(Data: Pointer);
|
|
|
-begin
|
|
|
- if Data=nil then ;
|
|
|
- ReleaseComponents;
|
|
|
-end;
|
|
|
|
|
|
procedure TFresnelApplication.DoBeforeFinalization;
|
|
|
var
|
|
@@ -225,52 +215,6 @@ begin
|
|
|
DoHandleAsyncCalls;
|
|
|
end;
|
|
|
|
|
|
-procedure TFresnelApplication.ReleaseComponents;
|
|
|
-var
|
|
|
- Component: TComponent;
|
|
|
- IsReferenced: Boolean;
|
|
|
-begin
|
|
|
- if FComponentsReleasing<>nil then exit; // currently releasing
|
|
|
- if (FComponentsToRelease<>nil) then begin
|
|
|
- if FComponentsToRelease.Count=0 then begin
|
|
|
- FreeAndNil(FComponentsToRelease);
|
|
|
- exit;
|
|
|
- end;
|
|
|
- // free components
|
|
|
- // Notes:
|
|
|
- // - check TLCLComponent.LCLRefCount=0
|
|
|
- // - during freeing new components can be added to the FComponentsToRelease
|
|
|
- // - components can be removed from FComponentsToRelease and FComponentsReleasing
|
|
|
- FComponentsReleasing:=FComponentsToRelease;
|
|
|
- FComponentsToRelease:=nil;
|
|
|
- try
|
|
|
- while (FComponentsReleasing<>nil) and (FComponentsReleasing.Count>0) do
|
|
|
- begin
|
|
|
- Component:=TComponent(FComponentsReleasing[0]);
|
|
|
- FComponentsReleasing.Delete(0);
|
|
|
- IsReferenced:=false; // (Component is TFresnelElement) and (TFresnelElement(Component).RefCount>0);
|
|
|
- if IsReferenced then
|
|
|
- begin
|
|
|
- // add again to FComponentsToRelease
|
|
|
- ReleaseComponent(Component);
|
|
|
- end else begin
|
|
|
- // this might free some more components from FComponentsReleasing
|
|
|
- Component.Free;
|
|
|
- end;
|
|
|
- end;
|
|
|
- finally
|
|
|
- // add remaining to FComponentsToRelease
|
|
|
- while (FComponentsReleasing<>nil) and (FComponentsReleasing.Count>0) do
|
|
|
- begin
|
|
|
- Component:=TComponent(FComponentsReleasing[0]);
|
|
|
- FComponentsReleasing.Delete(0);
|
|
|
- ReleaseComponent(Component);
|
|
|
- end;
|
|
|
- FreeAndNil(FComponentsReleasing);
|
|
|
- end;
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
constructor TFresnelApplication.Create(AOwner: TComponent);
|
|
|
begin
|
|
|
inherited Create(AOwner);
|
|
@@ -444,7 +388,7 @@ procedure TFresnelApplication.Idle(Wait: Boolean);
|
|
|
var
|
|
|
Done: Boolean;
|
|
|
begin
|
|
|
- ReleaseComponents;
|
|
|
+
|
|
|
ProcessAsyncCallQueue;
|
|
|
|
|
|
Done := True;
|