Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Windows tötet Delphi-Anwendung noch vor Unit-Finalisierung (https://www.delphipraxis.net/187698-windows-toetet-delphi-anwendung-noch-vor-unit-finalisierung.html)

Der schöne Günther 24. Dez 2015 10:23

AW: Windows tötet Delphi-Anwendung noch vor Unit-Finalisierung
 
Zitat:

Zitat von Sir Rufo (Beitrag 1325210)
Borlacadero

Hört sich an wie eine Darmerkrankung :kotz:

// 1. Update

Und mein Verdacht erhärtet sich! Wenn ich in meinem
Delphi-Quellcode:
WM_ENDSESSION
das Hauptformular abbaue, wird die Anwendung von Windows gekillt. Er scheint wirklich zu meinen "So, sind ja alle Fenster weg, können wir hier ja zumachen". Ein einfaches Form1.Destroy() reicht schon, alles danach wird nicht mehr ausgeführt!

Was ist nun wenn wir das Hauptformular nicht zerstören? Wie Raymon Chen schon sagte:
Zitat:

Besides, why spend your time closing windows when the session is about to go away anyway? Ooh, let me clean up this and destroy that, I know you asked to shut down, but this’ll just take a few seconds. It’s like taking the time to steam-clean the rugs before you demolish the building. Wasted effort.
Mein QuickFix sieht so (schlimm) aus:

Delphi-Quellcode:
destructor TForm1.Destroy;
begin
   if (Application.MainForm = self) then
      // do nothing
   else
      inherited;
end;
Was geschieht dann? Alles was ich möchte. Die Anwendung wird ordentlich beendet, die Dinge im finalization-Abschnitt der Unit werden ausgeführt und der Klassendestruktor auch. War es doch so einfach? :wiejetzt::party:


// 2. Update

Und die Bestätigung ist wohl auch da. Die Anwendung geht reproduzierbar tot wenn ich beim Herunterfahren nur sage
Delphi-Quellcode:
WinApi.Windows.DestroyWindow(Form1.Handle);
Tja, die Doku zu WM_ENDSESSION sagte
Zitat:

The application need not call the DestroyWindow or PostQuitMessage function when the session is ending.
"Need not call" ist nach meinem Englisch "muss nicht".

Hätte ich Idiot ausnahmsweise mal die Kommentare auf der MSDN-Seite weiter unten geleasen. Ein werter Herr bestätigt exakt meine Erlebnisse:
Zitat:

The documentation says you need not call DestroyWindow() inside your WM_ENDSESSION handler, but in my experience you *must* not call DestroyWindow(). Otherwise, the system might nuke your process before DestroyWindow() returns.
Das ist es also. Was wäre nun ein ordentliches Ende für diese Odyssee? Ich tue mich schwer auf eine konkrete Stelle im VCL-Code zu zeigen und zu sagen "Das sollte anders gemacht werden".


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:34 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz