Autor Beitrag
Bronstein
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Di 04.07.06 13:34 
Habe eine Anwendung (Formular mit eingabefeldern usw.).
Wenn dieses Formular jetzt den Focus verliert möchte ich, dass ein Ereignis auftritt.
Sprich wenn ich das Programm minimiere, auf den Desktop mit der Mausklicke oder wenn ich ein anderes Programm aufrufe.

Gibt es so ein Ergeinis und wenn ja wie heißt es bzw. wie kann ich das implementieren

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Di 04.07.06 13:42 
OnDeactivate

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Di 04.07.06 13:46 
deine Variable Application hat eine Ereignisroutine OnDeactivate, die du dafür verwenden kannst...

dafür musst du in deinem MainForm eine Funktion ergänzen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
type
  TMainForm = class(TForm)
  {...}
    procedure AppDeactivate(Sender: TObject);
  private
  {...}
  public
  {...}
  end;

{...}

implementation

procedure TMainForm.FormCreate(Sender: TObject);
begin
  {...}
  Application.OnDeactivate := AppDeactivate;
  {...}
end;

procedure TMainForm.AppDeactivate(Sender: TObject);
begin
  {... Do Something...}
end;


Edit: Alias5000 war schneller... klar... du kannst auch das OnDeactivate deiner Forms dafür verwenden, dann müsstest du aber gegebenenfalls für jedes Form diese Funktion nachpflegen... im Application.OnDeactivate kannst du das an zentraler Stelle... es bietet sich auch die TApplicationEvents- Komponente dafür an
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Di 04.07.06 13:56 
Klar, aber er will ja anscheinend nur für ein Formular, wenn man der Überschrift folgt :wink:

_________________
Programmers never die, they just GOSUB without RETURN
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Di 04.07.06 14:01 
so kann es klappen.

Wie kann ich wenn das Ereignis TForm1.ApplicationEvents1Deactivate auftritt, das Preogramm wieder aktivieren. So dass das Formular wieder sichtbar ist.

Das benötige ich, da ich mit einer Datenbank arbeite und diese erst wieder gesperrt wird wenn man auf speichern klickt. genau das möchte ich hier abfragen

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Di 04.07.06 14:30 
ZU meiner vorherigen Frage ist das die Antwort:
Application.Restore

Das Ereignis tritt aber nicht auf wenn ich zu einem anderen Programm wechsle möchte ich auch, dass das Programm sichtbar bleibt bis man die Daten gespeichert hat.
Doch das Ereignis tritt da nicht auf, auch wenn ich einfach neben meinem Programm auf den Desktop klicke soll das Programm aktiviert werden

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Di 04.07.06 14:49 
okay... warte mal... lass mich mal zusammenfassen, ob ich das, was du willst, richtig verstanden habe:

Du hast eine Datenbankanwendung geschrieben. In deiner Eingabemaske hast du einen Speichern- Knopf. Du möchtest verhindern, dass deine Anwendung erst "deaktiviert" werden kann, wenn man vorher auf Speichern gedrückt hat. Ansonsten soll dein Programm wieder in den Vordergrund gestellt werden, sobald man zu einer anderen Anwendung wechselt oder auf den Desktop klickt oder die Anwendung minimiert, ja ?
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Di 04.07.06 14:51 
ganz genau das ist mein Problem

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Di 04.07.06 15:13 
dann mach doch einfach im Deactivate einen

MessageDlg('Noch ungespeicherte Änderungen. bla. Jetzt speichern?', mtWarning, [mbYes, mbNo], 0)

und wenn ja angegeben wird, speicherst du... denke, es ist extrem anwenderunfreundlich, wenn ich nicht ein anderes Prog öffnen kann oder sonst irgendwas machen darf...
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Di 04.07.06 15:57 
Ja so hatte ich das vor, aber der springt mir überhaupt nicht in diese prozedure, wenn ich zu einem anderen Programm wechsle auf den Desktop klicke

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Di 04.07.06 16:24 
hab das gerade mal bei mir ausprobiert... bei mir wird eher das Event zu oft aufgerufen ;)

also folgenden Quelltext hab ich... hab hier ein form mit einem button und den appmessages:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.ApplicationEvents1Deactivate(Sender: TObject);
begin
  if Button1.Tag = 0 then begin
    Button1.Tag := 1;
    BringWindowToTop(Handle);
    ShowMessage('Zuerst den Knopf drücken!');
    Button1.Tag := 0;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Button1.Tag <> 2 then
    Button1.Tag := 2
  else
    Button1.Tag := 0;
end;


denke, dir fehlte das BringWindowToTop. Damit wird deine Anwendung wieder in den Vordergrund gestellt und deine Message angezeigt...
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Mi 05.07.06 07:54 
Ja OK das funktioniert so einigermaßen, das Ereignis tritt zumindest immer auf.

Wenn ich aber unten in der Startleiste/ Taskleiste ein anderes Programm auswähle, tritt zwar das Ereignis auf. Das andere Programm überdeckt aber trotzdem mein Programm.

Wie bring ich mein Programm also vor das andere Programm das ich unten ausgewählt habe.

Mit den Befehlen funktioniert es nicht:
- BringWindowToTop(Handle);
- Application.Restore;
- FormStyle := fsStayOnTop; //Form in den "StayOnTop" Modus bringen
FormStyle := fsNormal; //Form wieder "normalisieren"
- Form1.Show

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Mi 05.07.06 08:24 
ein bisserl kannst du hier doch auch mal im forum suchen Suche in: Delphi-Forum, Delphi-Library SETFOREGROUNDWINDOW... dann stolperst du über dutzende Threads mit einer ähnlichen Problematik


das, was dir wohl am meisten helfen kann würdest du in diesem Thread finden.