How to show this splash screen in 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. Thank.

+3
source share
3 answers

Inside the 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 the splash screen block:

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 displayed for at least 3 seconds or more if more time is required to create all forms of your application.

+5
source

, , , , , 3 .

.dpr

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;

, "", , 3000 (3 )

procedure TForm2.Timer1Timer(Sender: TObject);
begin
  Self.Close;
end;
+3

You must use a timer whose interval you set to 3000 (3 (s) * 1000 (ms)). Enabled must be set to true. In the default Timer event, you add code that is designed to display the main form.

+1
source

Source: https://habr.com/ru/post/1757471/


All Articles