Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show this splash screen for 3 seconds?

I created my splash screen using the method mentioned here: http://delphi.about.com/od/formsdialogs/a/splashscreen.htm

I need to show the splash screen for 3 seconds before showing the main form.

Please help. Thanks.

like image 961
Isamtron Avatar asked Jul 31 '10 14:07

Isamtron


People also ask

How do you keep splash screen for 2 seconds?

how to create a splash screen (timed: shows when app loads and and after 2 seconds goes to home screen. Create your splash screen and add a new event "on load page" with the action "pause" (2000 ms) and add another action "link to" (and select home screen).

How do I set the time on my splash screen?

you can use Sleep method like this in your Splash Activity onCreate method: Thread timer1 = new Thread(){ @Override public void run(){ try{ sleep(4000); } catch (InterruptedException e){ e. printStackTrace(); } finally{ Intent intent = new Intent(SplashActivity. this, NextActivity.


2 Answers

Inside project file:

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  uSplashScreen in 'uSplashScreen.pas' {frmSplashScreen};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;

  frmSplashScreen := TfrmSplashScreen.Create(nil);
  try
    frmSplashScreen.Show;
    // Create your application forms here
    Application.CreateForm(TForm1, Form1);

    while not frmSplashScreen.Completed do
      Application.ProcessMessages;
    frmSplashScreen.Hide;        
  finally
    frmSplashScreen.Free;
  end;

  Application.Run;
end.

Inside splash screen unit:

unit uSplashScreen;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TfrmSplashScreen = class(TForm)
    Timer1: TTimer;
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    Completed: Boolean;
  end;

var
  frmSplashScreen: TfrmSplashScreen;

implementation

{$R *.dfm}

procedure TfrmSplashScreen.FormShow(Sender: TObject);
begin
  OnShow := nil;
  Completed := False;
  Timer1.Interval := 3000; // 3s minimum time to show splash screen
  Timer1.Enabled := True;
end;

procedure TfrmSplashScreen.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  Completed := True;
end;

end.

The splash screen will be visible for minimum time of 3 seconds or more if it will take more time to create all the forms of your application.

like image 108
pani Avatar answered Sep 22 '22 22:09

pani


To achieve what you want you can follow the method described in the link you provided, and on The splash screen's form code you put a timer which gets fired after 3 seconds and closes the form.

Main .dpr file

var SplashScreen : TForm2;

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;

  SplashScreen := TForm2.Create(nil); // Creating with nil so this is not registered as main form
  try
    SplashScreen.ShowModal; // Blocking the execution for as long as this form is open
  finally
    SplashScreen .Free;
  end;

  Application.CreateForm(TForm1, Form1);
  Application.Run;

On the form which will be the 'splash screen' add the timer, enabled at 3000 interval (3s)

with the following event handler

procedure TForm2.Timer1Timer(Sender: TObject);
begin
  Self.Close;
end;
like image 33
zz1433 Avatar answered Sep 26 '22 22:09

zz1433