Autor Beitrag
Airtrox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Mi 16.12.09 00:06 
Abend,

ich will beim Schließen eines Formulars eine Abfrage starten, ob wirklich geschlossen werden soll. Nun, klappt es leider nicht ganz so wie ich will:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
     var
    AMsgDialog: TForm;
begin
AMsgDialog := CreateMessageDialog('Wirklich beenden?', mtWarning, [mbYes, mbNo]);
 with AMsgDialog do
    try
       Caption := 'Metropolis';

          case ShowModal of
             ID_YES: application.Terminate;
             ID_NO: action:=caNone;      // hier hackts
          end;

    finally
    free;
 end;

Habe ein wenig gegooglet und leider keine Lösung gefunden, die passen könnte. Das Problem liegt beim "Nicht-Schließen" falls Nein gedrückt wurde...


Moderiert von user profile iconNarses: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Di 15.12.2009 um 23:15
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 16.12.09 00:16 
Moin!

Probier das mal so: :idea:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if MessageDlg('Wirklich beenden?',mtConfirmation,mbOKCancel,0) <> mrOK then
    Action := caNone;
cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mi 16.12.09 00:36 
Schließen.. Abfrage..
Da gibt es doch sogar ein gleichnamiges Event: OnCloseQuery.

_________________
PROGRAMMER: A device for converting coffee into software.
Airtrox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Mi 16.12.09 00:37 
edit: Super, klappt so :)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19313
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 16.12.09 02:52 
Und um das noch einmal deutlich zu betonen:
Wenn man das tatsächlich statt im von user profile iconXentar erwähnten OnCloseQuery in OnClose macht, dann handelt man sich Probleme mit Windows ein, da das so nicht vorgesehen ist.

Windows fragt z.B. beim Herunterfahren zuerst an, ob das so in Ordnung ist. Genau dafür dient OnCloseQuery auch. Wenn man jetzt dort vorspiegelt, dass alles ok sei, dann aber das Beenden in OnClose doch abbricht, dann treten genau die nervigen Effekte auf, die manchmal beim Herunterfahren auftreten:
Irgendein Programm hängt, trotzdem kann man nicht einmal mehr den Taskmanager oder ein anderes Programm öffnen, da ja Windows schon denkt, es könne herunterfahren usw.

Deshalb: Das Abbrechen des Schließens sollte ausschließlich in OnCloseQuery passieren...
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Mi 16.12.09 10:16 
user profile iconNarses hat folgendes geschrieben Zum zitierten Posting springen:
Moin!

Probier das mal so: :idea:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if MessageDlg('Wirklich beenden?',mtConfirmation,mbOKCancel,0) <> mrOK then
    Action := caNone;
cu
Narses


Es gibt Softwareentwickler, die wegen geringerem Unfug erschossen wurden, Narses. :D

OnCloseQuery ist ja wohl die einzig richtige Lösung des Problems.

Beste Grüße
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 16.12.09 10:36 
Moin!

user profile iconTastaro hat folgendes geschrieben Zum zitierten Posting springen:
Es gibt Softwareentwickler, die wegen geringerem Unfug erschossen wurden, Narses. :D

OnCloseQuery ist ja wohl die einzig richtige Lösung des Problems.
Steht da irgendwo, dass ich diese Lösung empfehle? :gruebel: Kennt ihr den exakten Anwendungszweck dieses Ansatzes? :nixweiss: Ich habe auf die Frage geantwortet, mehr nicht. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Airtrox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Mi 16.12.09 15:17 
Heißt das im Klartext, dass ich die von mir geanannten Source bei OnCloseQuery einfügen soll ( klappt nicht, Fehler an der selben Stelle) oder die von Narses bei OnCloseQuery?
Wie wäre denn meine Variante richtig formuliert, denn sie ist mir lieber, damit kann man den Fenstertext noch definieren :)
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mi 16.12.09 15:33 
probiermal

ausblenden Delphi-Quelltext
1:
2:
3:
if MessageDlg('Wollen sie echt wirklich jetzt in diesem moment und keine anderen auf jeden fall auf der stelle mein Programm beenden?', mtConfirmation, [mbYes,mbNo],0) = mrYes then
  CanClose := True
else CanClose := False;


und das bitte ins CloseQuery.

Erklärung: die Variable/den Parameter Action gibt es im CloseQuery nicht ;)

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.


Zuletzt bearbeitet von elundril am Mi 16.12.09 15:34, insgesamt 1-mal bearbeitet
DonManfred
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148
Erhaltene Danke: 2

Windows 7
Delphi XE3 Pro + HTML5Builder
BeitragVerfasst: Mi 16.12.09 15:33 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure Tfrmppday.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  // Mach deine Prüfungen....
  // ... und dann setze
  CanClose := True; // oder false, je nach Bedarf ob das Fenster geschlossen werden darf oder nicht...
end;

_________________
Gruss Manfred
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 16.12.09 18:25 
Moin!

user profile iconAirtrox hat folgendes geschrieben Zum zitierten Posting springen:
denn sie ist mir lieber, damit kann man den Fenstertext noch definieren :)
Den Fenstertitel für Dialoge/Messageboxen kannst du doch global in den Projekteigenschaften einstellen, das würde ich eh nicht so machen. :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Dude566
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1592
Erhaltene Danke: 79

W8, W7 (Chrome, FF, IE)
Delphi XE2 Pro, Eclipse Juno, VS2012
BeitragVerfasst: Mi 16.12.09 19:46 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Und um das noch einmal deutlich zu betonen:
Wenn man das tatsächlich statt im von user profile iconXentar erwähnten OnCloseQuery in OnClose macht, dann handelt man sich Probleme mit Windows ein, da das so nicht vorgesehen ist.

Windows fragt z.B. beim Herunterfahren zuerst an, ob das so in Ordnung ist. Genau dafür dient OnCloseQuery auch. Wenn man jetzt dort vorspiegelt, dass alles ok sei, dann aber das Beenden in OnClose doch abbricht, dann treten genau die nervigen Effekte auf, die manchmal beim Herunterfahren auftreten:
Irgendein Programm hängt, trotzdem kann man nicht einmal mehr den Taskmanager oder ein anderes Programm öffnen, da ja Windows schon denkt, es könne herunterfahren usw.

Deshalb: Das Abbrechen des Schließens sollte ausschließlich in OnCloseQuery passieren...


Das ist ja mal interessant, wieder was dazu gelernt, habe sonst auch eine Abfrage ins normale OnClose gemacht.

_________________
Es gibt 10 Gruppen von Menschen: diejenigen, die das Binärsystem verstehen, und die anderen.