Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   SplashScreen Problem (https://www.delphipraxis.net/122584-splashscreen-problem.html)

Störtebeker 18. Okt 2008 23:28


SplashScreen Problem
 
Hallo,

kleine Nebenbemerkung: Ich arbeite in Lazarus:

ich verwende für mein Programm einen Splash und wollte nun etwas kombinieren, von dem meine vorherige Programme jeweils nur eines besaßen.

Kombination: ProgressBar und Label

Code der Programm-Unit

Delphi-Quellcode:
program Project;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms
  { you can add units after this }, main, robots, splash;

{$IFDEF WINDOWS}{$R manifest.rc}{$ENDIF}

begin
  Application.Initialize;

  Form3 :=TForm3.Create(Application);
  with TForm3.Create(nil) do
  try
  Form3.show;
  Form3.Update;

  Application.Initialize;
  ProgressBar1.Max:=100;
  Show;
  Update;
  Application.Title:= 'Project';
  Application.CreateForm(TForm1, Form1);
  ProgressBar1.StepBy(30);
  Application.CreateForm(TForm2, Form2);
  ProgressBar1.StepBy(80);
  Finally
  free;
  Form3.visible :=false;
  end;
  Application.Run;
end.
Codeausschnitt für eines der weiteren Formulare:
Delphi-Quellcode:
.
.
.
procedure TForm2.FormCreate(Sender: TObject);
begin
sleep(2500);
Form2.DoubleBuffered := true;
Form3.Label8.Caption:='System will be analyzed...';
Form3.Refresh;
end;
.
.
.
Also, der Splash erscheint, die Progressbar lädt. Gleichzeitig soll ein Label anzeigen, was das Programm gerade macht. Ohne ProgressBar funzt es. Aber nicht mit der ProgressBar. Was muss ich machen, damit die Kombination funktioniert?

Die Muhkuh 18. Okt 2008 23:38

Re: SplashScreen Problem
 
Du musst die ProgressBar auch noch neu zeichnen.

blawen 18. Okt 2008 23:41

Re: SplashScreen Problem
 
Hast Du es schon mal mit Application.ProcessMessages versucht?

Störtebeker 18. Okt 2008 23:46

Re: SplashScreen Problem
 
:wiejetzt:

@Die Muhkuh:
Delphi-Quellcode:
Application.Initialize;
  ProgressBar1.Max:=100;
  Show;
  Update;
ich dachte, dass in diesem Fall "Show" und "Update" dafür verantwortlich sind.

@blawen: Bei "Application.ProcessMessages" würde ich ehrlichgesagt Neuland betreten.
Sprich, hätte nicht die geringste Ahnung der Verwendung.

Die Muhkuh 18. Okt 2008 23:46

Re: SplashScreen Problem
 
Warum überhaupt das Sleep mit 2,5 Sekunden?

Störtebeker 18. Okt 2008 23:48

Re: SplashScreen Problem
 
Das sleep verwende ich, damit der SplashScreen auch seine Wirkung hat und nicht nach ner Sekunde wieder weg ist. Habe ich bis jetzt immer so gemacht.

Die Muhkuh 18. Okt 2008 23:50

Re: SplashScreen Problem
 
Ist aber nicht Sinn und Zweck davon, einfach mal so 2,5 Sekunden zu warten, nur damit man das Ding sieht.

Du musst noch jedem Ändern des Wertes der ProgressBar ein .Refresh aufrufen, sonst geht das nicht.

Störtebeker 18. Okt 2008 23:55

Re: SplashScreen Problem
 
Du meinst so:

Delphi-Quellcode:
program Project;

{$mode objfpc}{$H+} 

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads} 
  cthreads,
  {$ENDIF}{$ENDIF} 
  Interfaces, // this includes the LCL widgetset
  Forms
  { you can add units after this }, main, robots, splash;

{$IFDEF WINDOWS}{$R manifest.rc}{$ENDIF} 

begin
  Application.Initialize;

  Form3 :=TForm3.Create(Application);
  with TForm3.Create(nil) do
  try
  Form3.show;
  Form3.Update;

  Application.Initialize;
  ProgressBar1.Max:=100;
  Show;
  Update;
  Application.Title:= 'Project';
  Application.CreateForm(TForm1, Form1);
  ProgressBar1.StepBy(30);
  ProgressBar1.Refresh;
  Application.CreateForm(TForm2, Form2);
  ProgressBar1.StepBy(80);
  ProgressBar1.Refresh;
  Finally
  free;
  Form3.visible :=false;
  end;
  Application.Run;
end.
bringt leider auch nichts.

blawen 19. Okt 2008 00:29

Re: SplashScreen Problem
 
Eine kleine Erklärung zu Processmessages findest Du z.B. hier:

In meinem (gekürzten) Bsp. rufe ich ein Intro-Fenster auf und aktualisiere darin die Progressbar.
(In diesem Bsp. arbeite ich ohne Processmessages)

Delphi-Quellcode:
var
 Intro : TSplashScreen;

begin
  Application.Title := 'XY';
  Application.CreateForm(TFMainform, FMainform);
  Application.Initialize;
  Intro:=TSplashScreen.Create(Application);
  Try
    Intro.Show;
    Intro.UpDate;
    sleep(1000);
    Intro.Hide;
    Application.CreateForm(TFLogin, FLogin);
  Finally
    Intro.Free;
  End;
  .
  .
  { Passwortabfrage wird nach dem Intro ausgeführt }
  FLogin.ShowModal;
  .
  .
  { Passwortabfrage erfolgreich }
  { Intro-Fenster wird wieder eingeblendet und die Progressbar sichtbar gemacht }
    TRY
      Intro:=TSplashScreen.Create(Application);
      Intro.ProgressBar1.Visible := True;
      Intro.Show;
      Intro.UpDate;

      Intro.ProgressBar1.Position := 5;
      Application.CreateForm(TFMD, FMD);

      Intro.ProgressBar1.Position :=10;
      Application.CreateForm(TFPLZ_Ort_Ausw, FPLZ_Ort_Ausw);
      .
      .
      .
      Intro.ProgressBar1.Position := 90;
      Application.CreateForm(TFImportExport, FImportExport);

      Intro.Hide;
      Intro.Free;
      Application.Run;
    Except
      ShowMessage('Initialisierungsfehler');
      Application.Terminate;
      Application.Free;
    end;
end.

Garfield 19. Okt 2008 09:45

Re: SplashScreen Problem
 
Zitat:

Zitat von Störtebeker
bringt leider auch nichts.

Ich würde das Refresh nicht auf die ProgressBar sondern die Form3 anwenden.


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:38 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz