Autor Beitrag
Jukka
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Di 24.10.06 13:50 
Hallo,

Ich habe vor eine art loadingscreen in mein Programm einzubauen um dateien vorzuladen, Das geht auch alles jedoch bleibt da dann das problem. Ich lass den LoadingScreen erstellen und anzeigen , das mainform wird gehidet. Das Programm läd der LoadingScreen wird geschlossen und das eigentliche Programm angezeigt. Nun das Problem: Schließ ich das Formular sind keine Formulare mehr da ja, aber das Programm beendet einfach nicht. Es steht noch imemr im TaskManager


Projektcode:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
program Editor;

uses
  Forms,
  main in 'src\main.pas' {Form1},
  loadingunit in 'src\loadingunit.pas' {LoadingScreen};

{$R res\Editor.res}

begin
  Application.Initialize;
  Application.CreateForm(TLoadingScreen, LoadingScreen);
  Application.CreateForm(TForm1, Form1);
  Form1.Hide; 
  Application.Run;
end.


Loadingscreen
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
unit loadingunit;


uses main;

{$R *.dfm}

// nur zum testen
procedure TLoadingScreen.Timer1Timer(Sender: TObject);
begin
  Progressbar1.Max := 100;
  Progressbar1.Position := Progressbar1.Position + 1;
  if Progressbar1.Position = 100 then begin
    Timer1.Enabled := FALSE;
    Form1.Show;
    LoadingScreen.Hide;
  end;
end;


Eigentliche programm
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
close;// <- geht nicht

Application.Close;// <- geht auch nicht
end;



Was mach ich falsch?

MfG Ju
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Di 24.10.06 14:10 
Form1 ist die Hauptform, ja?

Also im FormClose ein Close; einzusetzen bringt ja nichts, außer nen Überlauft denn dann wird ja immer und immer wieder FormClose aufgerufen.. lass beides einfach ganz weg..

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
Jukka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Di 24.10.06 14:22 
Ich weiß nicht welches das Hauptform ist aber wenn ich den loadingscreen close ist das Programm zuende also denke ich mal das es das ist.

Wie kann ich das Hauptform nach dem laden ändern?
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Di 24.10.06 14:35 
das Hauptformular kannst du unter Projekt > Optionen > Formulare bei Hauptforumlar einstellen. Form1 ist normalerweise das Hauptformular, deshalb musst du auch, wenn das Programm beendet werden soll Form1.Close schreiben.

Ändern kannst du das Hauptformular mit Application.MainForm := Form1.

Ach ja, den Startbildschirm lässt man normalerweise per Hand anzeigen:

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:
program Editor;

uses
  Forms,
  main in 'src\main.pas' {Form1},
  loadingunit in 'src\loadingunit.pas' {LoadingScreen};

{$R res\Editor.res}

begin
  LoadingScreen := TLoadingScreen.Create(Application); //Zur Laufzeit erstellen
  LoadingScreen.Show;
  try
    Application.MainForm := Form1;  //Hier und in den nächsten 3 Zeilen braucht er zum laden, und während er lädt soll er den startbildschirm anzeigen
    Application.Initialize;  
    Application.CreateForm(TForm1, Form1);  //wichtig ist, dass hier nicht Application.CreateForm(TLoadingScreen,LoadingScreen) steht!!!!!
  finally
    LoadingScreen.Hide;
    LoadingScreen.Free; //Freigeben
    Application.Run; //und dann gehts los
  end;
end.
Jukka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Di 24.10.06 14:58 
Zitat:
[Fehler] Editor.dpr(14): Einer Nur-Lesen Eigenschaft kann kein Wert zugewiesen werden
(auf Application.MainForm := Form1;)



Und wenn ich das so mache bzw als hauptformular Form1 einstell wird der LoadingScreen erst garnicht gezeigt
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Di 24.10.06 15:08 
ja, schade hab ich mich getäuscht. dann stellst du diese zeile einfach weg und stellst das bei den Projektoptionen ein.

user profile iconJukka hat folgendes geschrieben:
Und wenn ich das so mache bzw als hauptformular Form1 einstell wird der LoadingScreen erst garnicht gezeigt


komisch, bei mir schon ._.
aber ein fehler ist mir auch aufgefallen, der inhalt vom loadingscreen (zb. Labels) werden nicht angezeigt...

dann fällt mir nur noch eins ein: jedes Objekt vom loading Screen selber erstellen, like label1 := TLabel.create(Loadingscreen); label1.parent :........
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Di 24.10.06 15:29 
mal eine dirty variante (vermutlich gehts besser)

lass den Splashscreen das mainform sein, schließe es nicht sondern verstecke es (splashform.hide) und im onClose des "richtigen" Mainforms machst du ein application.close.

//edit hab mal noch eine Anwendung gefunden, die ein SplashScreen hat (elektro). Da hab ich das folgendermaßen gemacht (mainform ist form1):

ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
program Elektro;

uses
  Forms,
  ElektroU in 'ElektroU.pas' {Form1},
  exitdial in 'exitdial.pas' {Exitdia},
  schaltung in 'schaltung.pas' {Form2},
  splash in 'splash.pas' {Form3};

{$R *.RES}

begin
  Application.Initialize;
  Application.Title := 'Elektro';
  Form3:=Tform3.create(Application);
  form3.PageNo:=0;
  form3.TotalPages:=3;
  form3.doupdate;
  Application.CreateForm(TForm1, Form1);
  form3.DoUpdate;
  Application.CreateForm(TExitdia, Exitdia);
  form3.DoUpdate;
  Application.CreateForm(TForm2, Form2);
  form3.free;
  form3:=nil;
  Application.Run;
end.

//splash-unit:

...

type
  TForm3 = class(TForm)
    ...
  public
    { Public-Deklarationen }
    PageNo     : Integer;
    TotalPages : Integer;
    procedure DoUpdate;
  end;

var
  Form3: TForm3;

implementation

{$R *.DFM}
procedure TForm3.DoUpdate;
var i:integer;
begin
  { increment our pageno variable }
  inc(PageNo);  { show splash screen on first variable increment }
  if PageNo = 1 then  Show;
  { update our TGauge }
  for i:=1 to 10 do
  begin
    coolprogressbar1.position := Trunc((((pageno/10)*i)/TotalPages)*100);
    { update our splash screen }
    Update;
    if pageno<3 then sleep(50else sleep(10);
  end;
  Application.ProcessMessages;
end;

end.

HTH Frank
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 24.10.06 16:09 
So sollte es auch funktionieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
uses
 loadingunit;
...
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 LoadingScreen.Close;
end;
bei mir klappts ;)
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Di 24.10.06 16:19 
richtig, aber es verwirrt ;)
verwende am besten das beispiel nach dem edit,
da wird das Splashform unabhängig von der Formularliste des TApplication-Objektes erzeugt und wird vor dem richtigen Programmbeginn schon wieder freigegeben.

musst natürlich die automatisch erzeugte Zeile, die das Splashform erzeugt, löschen.

Gruß Frank
Jukka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Di 24.10.06 16:57 
Danke an alle hab die einfachste art genommen >_<