diff --git a/lcl/forms.pp b/lcl/forms.pp index c36550b241..645bf98c88 100644 --- a/lcl/forms.pp +++ b/lcl/forms.pp @@ -890,8 +890,10 @@ type FMouseControl: TControl; FNavigation: TApplicationNavigationOptions; FOldExceptProc: TExceptProc; + FOldExitProc: Pointer; FOnActionExecute: TActionEvent; FOnActionUpdate: TActionEvent; + FOnDestroy: TNotifyEvent; FOnHelp: THelpEvent; FOnHint: TNotifyEvent; FOnIdle: TIdleEvent; @@ -1020,6 +1022,7 @@ type property OnShortcut: TShortcutEvent read FOnShortcut write FOnShortcut; property OnShowHint: TShowHintEvent read FOnShowHint write FOnShowHint; property OnUserInput: TOnUserInputEvent read FOnUserInput write FOnUserInput; + property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy; property ShowHint: Boolean read FShowHint write SetShowHint; property Title: String read GetTitle write SetTitle; end; @@ -1252,7 +1255,8 @@ end; {$IFDEF ExceptionHasNoFrames} procedure ExceptionOccurred(Sender: TObject; Addr,Frame: Pointer); {$ELSE} -procedure ExceptionOccurred(Sender: TObject; Addr:Pointer; FrameCount:Longint; Frames: PPointer); +procedure ExceptionOccurred(Sender: TObject; Addr:Pointer; FrameCount: Longint; + Frames: PPointer); var FrameNumber: integer; {$ENDIF} @@ -1277,6 +1281,12 @@ Begin HandlingException:=false; end; +procedure BeforeFinalization; +// This is our ExitProc handler. +begin + FreeInterfaceObject; +end; + //------------------------------------------------------------------------------ // The focus state is just the focus count for now. To save having to allocate // anything, I just map the Integer to the TFocusState. @@ -1430,6 +1440,7 @@ end; procedure FreeInterfaceObject; begin //debugln('FreeInterfaceObject'); + if Application=nil then exit; Application.Free; Application:=nil; FreeAllClipBoards; diff --git a/lcl/include/application.inc b/lcl/include/application.inc index 240aa03201..ae49009191 100644 --- a/lcl/include/application.inc +++ b/lcl/include/application.inc @@ -96,6 +96,8 @@ begin inherited Create(AOwner); CaptureExceptions:=true; + FOldExitProc:=ExitProc; + ExitProc:=@BeforeFinalization; end; {------------------------------------------------------------------------------ @@ -105,7 +107,14 @@ destructor TApplication.Destroy; var HandlerType: TApplicationHandlerType; begin + if Self=nil then + RaiseGDBException('TApplication.Destroy Self=nil'); Include(FFlags,AppDestroying); + + if Assigned(FOnDestroy) then FOnDestroy(Self); + + ExitProc:=FOldExitProc; + DoFreeReleaseComponents; if OnMenuPopupHandler=@MenuPopupHandler then OnMenuPopupHandler:=nil; @@ -1409,6 +1418,9 @@ end; { ============================================================================= $Log$ + Revision 1.104 2005/02/26 20:43:54 mattias + TApplication now uses ExitProc to free itself before all finaizations + Revision 1.103 2005/02/26 20:26:03 mattias fixed hint size and activate