Autor Beitrag
anno2007
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Di 14.04.09 23:46 
Hi,
ich habe mal wieder ein Problem.

Ich habe 2 Formen in meinem Programm. Form2 wird vor Form1 gezeigt.
In Form2 nehme ich einige Einstellungen vor und kann dann entweder auf weiter (dann kommt Form1) oder auf schließen drücken.

Wenn ich jetzt auf schließen drücke soll sich das Programm logischerweise beenden (application.terminate). Allerdings wird noch ganz kurz das Form.Create von Form1 ausgeführt und dann erst geschlossen. Die ganze Zeit ist dann Form1 nur "aufgeblitzt" und dann hat sich das Programm beendet, das hat mich zwar genervt, war aber nicht weiter schlimm.
Allerdings hab ich jetzt eine Endlosschleife in Form1.Create drin, aus der ich nur rauskomme, wenn in Form2 Einstellungen getroffen wurden.
Da aber diese beim schließen vom Form2 nicht gemacht wurden und Form1.Create trotzdem ausgeführt wird sitze ich nun in einer sehr schönen Endlosschleife, aus der ich nie wieder rauskomme.

Das ist mein Project1 (ich weis nicht ob es was nutzt, aber ist da vielleicht ein Fehler drin?). Ich kann jetzt nicht das ganze Programm posten, das würde sich eh keiner anguggen.

[Spoiler]
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
  Form2 := TForm2.Create(nil);
  Form2.ShowModal;
  Form2.Free;

  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

[/Spoiler]

Ich würde mich freuen wenn mir irgendeiner Helfen kann :).

anno2007


Moderiert von user profile iconNarses: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Mi 15.04.2009 um 00:50
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 14.04.09 23:55 
Moin!

Runtergetippt, nicht getestet:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
begin
  Application.Initialize;
  Application.CreateForm(TForm2, Form2);
  Form2.ShowModal;
  if NOT Application.Terminated then begin
    Application.CreateForm(TForm1, Form1);
    Application.Run;
  end;
end.
cu
Narses

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

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Mi 15.04.09 00:10 
Hey,

Danke für deine Antwort.
Aber das will leider auch nicht so.
Die Idee scheint mir verständlich, aber TForm1.FormCreate wird immer noch ausgeführt. Zumindest für einen Bruchteil einer Sekunde, Showmessage wird ganz kurz angezeigt, verschwindet dann, aber aus der Schleife will er nicht raus.

anno2007
anno2007 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Do 16.04.09 12:06 
Sry für den Doppelpost,
aber ich möchte den Post mal wieder *pushen*.

Hat sonst wirklich keiner eine Idee.
Es wäre schon wichtig, weil man mein Programm sonst aus Form2 raus nicht beenden kann.
Ich wäre euch für eure Hilfe echt verdammt dankbar. :wink:

Thx
anno2007
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 16.04.09 12:42 
Application.Terminate sendet eine MESSAGE, zum beenden des Programms. Diese Messages werden allerdings erst in Application.Run abgearbeitet.

Vorschlag:
Auch wenn es unschön ist, nimm eine globale Variable, und nur wenn diese true ist, erzeugst du dein Form1.

Btw.: Nenn deine Formulare um ;)

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

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Do 16.04.09 12:50 
Es hat geklappt!!!!!!! :).

Dankeschön Xentar, aber auch Narses für die Mühe!
Ja, die Formulare werd ich mal umbenennen :D.

anno2007