Autor Beitrag
Timelesk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 82


Delphi 2006 Prof
BeitragVerfasst: Mo 10.07.06 14:31 
Hallo,

ich hänge an folgendem Problem:

Meine Projekt-Datei sieht folgendermaßen aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
program Programm;

uses
  Forms,
  map in 'units\map.pas' {karte},
  hauptform in 'units\hauptform.pas' {main},
  ueber in 'units\ueber.pas' {about},
  ergebnis in 'units\ergebnis.pas' {result},
  protokoll in 'units\protokoll.pas' {proto},
  bestenliste in 'units\bestenliste.pas' {score},
  bestenliste_name in 'units\bestenliste_name.pas' {score_name},
  first_screen in 'units\first_screen.pas' {SplashScreen},
  modules in 'units\modules.pas' {modul};

{$R *.res}

begin
  Application.CreateForm(Tmodul, modul);
  Application.Initialize;
  Application.Run;
end.


Wie man sieht, wird nur das Form Modul erzeugt und angezeigt!
Nun wähle ich in diesem Form aus einer Listbox einen Wert aus und führe dann die Procedure load_modul(string); aus:

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:
procedure Tmodul.load_modul(name: string);
begin
  modul.Hide;
  modul_add := name + '_';
  Application.CreateForm(TSplashScreen, SplashScreen);
  try
    SplashScreen.Show;
    SplashScreen.Update;
    Application.Title := 'GlobeMem - Vereinigte Staaten von Amerika';
    Application.HelpFile := '';
    Application.CreateForm(Tmain, main);
    main.bild.Picture := SplashScreen.bild.Picture;
    Application.CreateForm(Tabout, about);
    Application.CreateForm(Tkarte, karte);
    Application.CreateForm(Tresult, result);
    Application.CreateForm(Tproto, proto);
    Application.CreateForm(Tscore, score);
    Application.CreateForm(Tscore_name, score_name);
    SplashScreen.Hide;
  finally
    SplashScreen.Free;
    main.ShowModal;    //PROBLEM
  end;
end;


Und hier ist mein Problem!
Ich muss das Formular Modul immer selbstständig schließen!
Füge ich nach dem main.Show oder main.ShowModal ein modul.close; ein, wird das nicht ausgeführt!
Auch wird durch modul.Hide das Formular nicht versteckt und durch modul.Visible = false erst recht nicht!
wenn ich ein modul.Free einbaue, gibts nen Access-Error und wenn ich das modul.Close in die OnClose der Hauptform einbau, wird das auch nicht ausgeführt!

Bin ich gerade stockblind oder wo ist das Problem?

Würde mich freuen, wenn mir jemand auf die Sprünge helfen könnte...

gruß
Timelesk
Soulama
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72



BeitragVerfasst: Mo 10.07.06 15:39 
versuch mal diesen Kode:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  // Statt: Application.CreateForm(TSplashScreen, SplashScreen); 
  SplashScreen:= TSplashScreen.Create(nil);
  ...
  ...
  FreeAndNil(SplashScreen);
Peinhard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 39



BeitragVerfasst: Mo 10.07.06 15:40 
Ich kann dir zeigen, wie ich es manchmal mache - ohne LoadModul direkt aus der dpr heraus:

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 Sonstewas;

uses
  Forms,
  SysUtils,
  Intro in 'Intro.pas' {IntroForm},
  Main in 'Main.pas' {MainForm},
  ... ;

{$R *.RES}

begin
  LongTimeFormat := 'hh:nn';
  ShortDateFormat := 'dd.mm.yyyy';
  Application.Initialize;
  Application.Title := 'Sonstewas';
  IntroForm := TIntroForm.Create(Application);
  IntroForm.Show;
  IntroForm.Update;
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.


Und in OnShow des Haupformulars dann:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TMainForm.FormShow(Sender: TObject);
begin
  if Assigned(IntroForm) then
  begin
    IntroForm.Gauge.Progress := 97;
    IntroForm.Update;
    Sleep(666); //damit man die 97 auch nochmal kurz sieht...
    IntroForm.Free;
    IntroForm := nil;
  end;
  ...
end;


Während des OnCreate des Hauptforms oder auch eines evt Datenmoduls kann auch immer auf IntroForm zuggriffen und zB die Gauge/Progressbar entsprechend gesetzt werden.

peinhard
Timelesk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 82


Delphi 2006 Prof
BeitragVerfasst: Mo 10.07.06 17:19 
Hi,

danke für eure Lösungen, aber ich glaube, ihr habt mein Problem falsch verstanden!
Der SplashScreen wird erfolgreich ausgeführt, nur um den dreht es sich gar nicht!

Beim Programmstart soll das Fenster Module angezeigt werden.
Man wählt sich ein Modul und dann wird das Programm erst geladen! Und während das Programm läd, wird der SplashScreen angezeigt.

@peinhard: Dein Code im OnShow der Hauptform funktioniert, bis ich das Hauptformular beende und somit das Programm! Dann kommt nämlich auch ein Access-Error!
Rufe ich das stattdessen mit main.Show; auf, kommt der Access-Error bereits beim anzeigen der Form.

:?:
Peinhard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 39



BeitragVerfasst: Mo 10.07.06 18:29 
Sorry, aber ich hatte dein Problem wohl wirklich nicht richtig verstanden. ich halte es aber für keine gute Idee, die eigentlich auf die *.dpr beschränkte Syntax Application.CreateForm() außerhalb derselben anzuwenden und so eine Art 'sub-dpr' zu schaffen. Entweder würde ich vom Loader aus - das im übrigen das Hauptform der ganzen Anwendung darstellt und schon aus diesem Grunde nicht mit Close oder gar Free bedacht werden sollte - die Forms auf die 'ganz normale Art' - Main := TMainForm.Create(Application) - aufrufen, oder wirklich das ganze in eigenständige Module sprich EXEn umzuwandeln, die der Loader aufrufen und sich danach beenden kann.

peinhard