Autor Beitrag
Dhakiyah
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 327
Erhaltene Danke: 5

Windows 7
Delphi XE2
BeitragVerfasst: Do 01.10.09 13:53 
Hallo!
Habe ein Programm und möchte das es egal wie ich es beende, die Abfrage kommt ob ich es beenden will.
Also wenn ich rechts oben das x drücke oder übers Menü Beenden oder unten rechts der Button beenden drücke.

Wie mache ich das?

Habe im Moment beim Button:
ausblenden Delphi-Quelltext
1:
2:
3:
begin
  if Application.MessageBox('Soll das Programm beendet werden?','Programm beenden',MB_YESNO+MB_IconQuestion) =IDYES then Close;
end;


Und beim OnClose vom Hauptfenster:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure Tfrm_mdi_main.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:= caFree;
  Application.Terminate;
end;


Was mir auch aufgefallen ist, wenn es beendet, dann dauert es ca. 20sec bis es wirklich komplett zu ist... Ist das normal???

_________________
Es ist soooo flauschig !!!
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: Do 01.10.09 13:57 
TForm.OnCloseQuery

_________________
PROGRAMMER: A device for converting coffee into software.
Dhakiyah Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 327
Erhaltene Danke: 5

Windows 7
Delphi XE2
BeitragVerfasst: Do 01.10.09 13:59 
Und dann??? Bzw. wie genau mache ich das?

_________________
Es ist soooo flauschig !!!
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 01.10.09 14:07 
Bevor eine Anwendung geschlossen wird, wird das OnCloseQuery-Event ausgelöst. In dieses packst du deine Messagebox rein, und setzt dann den parameter canClose entsprechend.

Den Code, den du jetzt im OnClose drin hast, würde ich einfach weglassen - oder ist das Fenster, das da grade geschlossen wird, nicht die Hauptform?

_________________
We are, we were and will not be.
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Do 01.10.09 14:10 
Es gibt Tform.canclose true/false bei false wird der Close Befehl einfach geschluckt.

Dafür im Objektinspektor bei deinem Formular um das es geht auf Ereignisse OnCloseQuerry.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if schließen then CanClose := true else CanClose := false;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Schliesen then Action := caFree else Action := caNone;
end;


Bevorzugt CloseQuery und wen du Action caFree machst dürfte das Application.Terminate unnötig sein.
Hab aber lange nicht mehr mit gearbeitet.


Zuletzt bearbeitet von thepaine91 am Do 01.10.09 14:11, insgesamt 2-mal bearbeitet
Dhakiyah Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 327
Erhaltene Danke: 5

Windows 7
Delphi XE2
BeitragVerfasst: Do 01.10.09 14:11 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure Tfrm_mdi_main.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
 if Application.MessageBox('Soll das Programm beendet werden?','Programm beenden',MB_YESNO+MB_IconQuestion) =IDYES then
 CanClose := true;
end;


Habe ich jetzt gemacht. Wie verweise ich jetzt im Butten auf die CloseQuery???

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure Tfrm_mdi_main.cmd_beendenClick(Sender: TObject);
begin
  FormCloseQuery();
end;


Geht nicht.


Ja, das ist die Hauptform.

_________________
Es ist soooo flauschig !!!
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Do 01.10.09 14:12 
mit TForm.close; ? ^^


Zuletzt bearbeitet von thepaine91 am Do 01.10.09 14:21, insgesamt 1-mal bearbeitet
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 01.10.09 14:12 
Du musst auch noch else canclose := False setzen. ;-)

Und in dem Button packst du einfach ein close; rein - das sollte dann reichen. :D

_________________
We are, we were and will not be.
Dhakiyah Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 327
Erhaltene Danke: 5

Windows 7
Delphi XE2
BeitragVerfasst: Do 01.10.09 14:16 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure Tfrm_mdi_main.cmd_beendenClick(Sender: TObject);
begin
  Close;
end;



procedure Tfrm_mdi_main.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
 if Application.MessageBox('Soll das Programm beendet werden?','Programm beenden',MB_YESNO+MB_IconQuestion) =IDYES then
  CanClose := true
 else
  CanClose := false;
end;


procedure Tfrm_mdi_main.mnu_beendenClick(Sender: TObject);
begin
  Close;
end;


Klappt :lol:

Brauche ich jetzt noch das normale OnClose?

Und woran kann das liegen, dass er nach beenden noch 10-20sec braucht, bis er wirklich komplett zu ist? Er springt immer ins Programm aber man kann halt noch auf Programm abbrechen drücken...

_________________
Es ist soooo flauschig !!!
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Do 01.10.09 14:17 
user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:
Du musst auch noch else canclose := False setzen. ;-)


Besser gleich so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure Tfrm_mdi_main.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  CanClose := Application.MessageBox('Soll das Programm beendet werden?''Programm beenden', MB_YESNO + MB_IconQuestion) = IDYES;
end;
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 01.10.09 14:19 
Ne, das OnClose würde ich in der Form dann weglassen. Kann sogar sein, dass das die Ursache ist - beim schließen sich selbst schließen ist irgendwie doppelt gemoppelt und rekursiv...

@Andreas L.: Klar, aber meins war für mich weniger Schreibarbeit. :mrgreen:

_________________
We are, we were and will not be.
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Do 01.10.09 14:20 
user profile iconDhakiyah hat folgendes geschrieben Zum zitierten Posting springen:

Brauche ich jetzt noch das normale OnClose?



user profile iconDhakiyah hat folgendes geschrieben Zum zitierten Posting springen:
Und woran kann das liegen, dass er nach beenden noch 10-20sec braucht, bis er wirklich komplett zu ist? Er springt immer ins Programm aber man kann halt noch auf Programm abbrechen drücken...


Hatte das mal bei einer ListView mit 25000 Einträgen, da hat das Programm auch ein bisschen gebraucht bis es zu war. Vielleicht hast du was derartiges?



user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:

@Andreas L.: Klar, aber meins war für mich weniger Schreibarbeit. :mrgreen:
:mrgreen:
Dhakiyah Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 327
Erhaltene Danke: 5

Windows 7
Delphi XE2
BeitragVerfasst: Do 01.10.09 14:22 
Also das Programm geht komplett zu. Nur bin ich dann in der IDE und muss 10-20 sec. warten bis ich weiter machen kann, außer ich drücke halt auf Programm beenden.
Naja, greife auf ne große Datenbank zu.
Vielleicht liegt es daran.

LG

_________________
Es ist soooo flauschig !!!
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Do 01.10.09 14:23 
user profile iconDhakiyah hat folgendes geschrieben Zum zitierten Posting springen:
Also das Programm geht komplett zu. Nur bin ich dann in der IDE und muss 10-20 sec. warten bis ich weiter machen kann, außer ich drücke halt auf Programm beenden.

Genau so ist es bei mir auch.

user profile iconDhakiyah hat folgendes geschrieben Zum zitierten Posting springen:
Naja, greife auf ne große Datenbank zu.
Vielleicht liegt es daran.

Wird wohl so sein ;-)