siehe
Beitrag #20, da bemerkt man, daß Delphi bei TThread die Thread-Prozedur (.Execute) schon mit einem Try-Except-Block absichert (zumindestens in "neueren" Delphiversionen)
k.A. ob's funktioniert
Delphi-Quellcode:
Program MyProgram;
Uses SysUtils, Forms, Unit1;
Var doRestart: Boolean;
Begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Repeat
doRestart := False;
Try
Application.Run;
Except
doRestart := True;
End;
Until doRestart and not Application.Terminated;
End.
hier hab ich mal alles verpackt und versucht die Finalisierung von Application nachzubauen:
Delphi-Quellcode:
Uses SysUtils, Classes, Forms, Unit1;
Function FindGlobalComponent(Const Name: String): TComponent;
Var i: Integer;
Begin
For i := 0 to Screen.FormCount - 1 do Begin
Result := Screen.Forms[i];
If not (csInline in Result.ComponentState) and
(CompareText(Name, Result.Name) = 0) Then Exit;
End;
For i := 0 to Screen.DataModuleCount - 1 do Begin
Result := Screen.DataModules[i];
If CompareText(Name, Result.Name) = 0 Then Exit;
End;
Result := nil;
End;
Var doRestart: Boolean;
Begin
Repeat
doRestart := False;
Try
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
Except
doRestart := True;
Try
If (Application <> nil) and (Application.Handle <> 0) Then Begin
Application.Minimize;
Application.ShowHint := False;
Application.Destroying;
Application.DestroyComponents;
End;
// If HintDoneEvent <> 0 Then CloseHandle(HintDoneEvent);
UnregisterFindGlobalComponentProc(FindGlobalComponent);
Except
End;
End;
Until doRestart and not Application.Terminated;
End.
aber eigentlich die die Nachrichtenbearbeitung des Hauptthreads (im .Run) auch per Try-Except abgesichert.