Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (1)


How to create your own splash screen in less than 3 minutes... Component available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 7.x (or higher)
Category:
Component Writing
Skill Level:
Scoring:
Last Update:
11/17/2008
Search Keys:
delphi delphi3000 article borland vcl code-snippet create a splash screen in delphi-7
Times Scored:
3
Visits:
2385
Uploader: Frank de Hell
Company:
Reference: http://www.superliegebeest.nl/delphi.php#3
Component Download: http://www.superliegebeest.nl/d7/eswg.zip
 
Question/Problem/Abstract:
This is a basic and very short tutorial for creating your own splash screen. The best way to learn Delphi is to have an example, and study the code. Do not rely on 3rd party components when you do not have to! Create your own splash screen in less than 3 minutes. Following this tutorial, you will learn to create a splash screen, that can be disabled by un checking a check box on the mainform, it makes use of an Inifile to store the value and enable and disable the appearance of the Splash screen. About the included example, to test the splash screen a simple restartbutton was added to it, in order to make that work Shellapi was added to the uses clausule of Form1.
Answer:




How to create your own splash screen in less than 3 minutes!
  

Quick Start

This is a basic and very short tutorial for creating your own splash screen. The best way to learn Delphi is to have an example, and study the code. Do not rely on 3rd party components when you do not have to! Create your own splash screen in less than 3 minutes. Following this tutorial, you will learn to create a splash screen, that can be disabled by un checking a check box on the mainform, it makes use of an Inifile to store the value and enable and disable the appearance of the Splash screen. About the included example, to test the splash screen a simple restartbutton was added to it, in order to make that work Shellapi was added to the uses clausule of Form1.



1.
Create a new project



2.
Add another form to it [menu File= New= Form]



3.
To the uses clausule of Form1 add: Inifiles

...

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls, IniFiles;

...





4.
To the private section of Form1 add: Inifile : Tinifile;

...

private

    IniFile: TIniFile

...



5.
Add the Unit2 to the uses clausule of Form1 just below Implementation

...

implementation



uses

  Unit2;



{$R *.dfm}

...



6.
Drop a check box on Form1 [Checkbox1], and a label [Label1], set the Label its caption property to: ShowSplash [or any Variable name, that you prefer to use as indicator that the check box serves for enabling and/or disabling the splash screen]





7.
Doubleclick Form1 and change the OnFormCreate event as below:


...

procedure TForm1.FormCreate(Sender: TObject);

var

   Splash: Boolean;

begin

Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));

with Inifile do

  try

    Splash:= ReadBool('ShowSplash','LastChoice', True );

    Checkbox1.Checked := Splash;

   if Splash then

   begin

     Sleep(1000);

     Form2.Close;

     Form2.Release;

   end;

  finally

    Free;

end;

end;

...


8.
Create the OnFormClose event on Form1 and change it to the following:

...

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

var

   Splash: Boolean;

begin

  Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));

  Splash := Checkbox1.Checked;

  with Inifile do

  try

   WriteBool('ShowSplash','LastChoice', Splash);

  finally

   Free;

  end;

end;

...


9.
Open Form2, add inifiles to the uses clausule  of Form2:

...

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtCtrls, IniFiles;

...



10.
Declare the boolean and the Tinifile just below the var section, after the Form2 declaration:

...

var

  Form2: TForm2;

  Splash: Boolean;

  Inifile: TIniFile;



implementation



{$R *.dfm}

...



11.
Below the inclusion of the Delphi Form [{$R *.dfm}], in Form2 add the following code between [...] :


...

implementation


{$R *.dfm}

[

initialization



Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));

  with Inifile do

    try

      Splash:= ReadBool('ShowSplash','LastChoice', True);

     finally

      Free;

    end;

    if Splash then

      begin

        Form2 := TForm2.Create(nil);

        Form2.Show;

        Form2.Update;

      end;

]

end.

    ...



12.
Change the borderstyle of Form2 to bsNone in the object inspector

Done!


Notes:
Of course a splash screen that has the default color and is empty, is not really cool so add an image to it, or anything you want to appear there, see the included example for a simple basic idea, but technically speaking you are finished and have just created your own Splash Screen, and you no longer have to rely on 3rd party components!

Note that variables can be called anything you wish [except for keywords etc], it is good practice to name them to something useful, so the name of it already tells you at least a bit what is it about. Then if you are finished with your project you can always do a search and place to make the variables shorter [saving a bit of space] and making them more difficult to guess, should you wanna'. Also, it is a good thing to name the components, and the forms, and units to something meaningful. The advantage of properly named forms, are so you can tell them apart from the standard forms with names given to them by delphi itself, and they wont be written over accidentally easy, plus it is easier to work with them in a single project that has more forms. However, for ease of use of this tutorial, I used the standard names.

The position can and maybe should be altered too, but this is purely personal, so I did not discuss that. In the included example, position of Form1 was set to poDesktopCenter, and position of Form2 was set to poMainformCenter, so the splashscreen appears centered in where the Form1 will appear. Also, for your own sake [readability] it is best to name your forms like something more clear. In this tutorial however, I used the standard names Delphi gives them, to not make it more complex and lengthy. My own splash screen would be named something like: SplashForm, while Form1 would be named: MainForm. Same goes for components, Checkbox1 does not say anything what it is used for or what it is about, I myself would name it something like: chkSplash.  



The finished forms are below:



Unit1.pas

================================================================

unit Unit1;


interface


uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls, IniFiles;


type

  TForm1 = class(TForm)

    Checkbox1: TCheckBox;

    Label1: TLabel;

    procedure FormCreate(Sender: TObject);

     procedure FormClose(Sender: TObject; var Action: TCloseAction);

  private

    IniFile: TIniFile;

  public

    { Public declarations }

  end;


var

  Form1: TForm1;


implementation


uses

  Unit2;



{$R *.dfm}



procedure TForm1.FormCreate(Sender: TObject);

var

   Splash: Boolean;

begin

Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));

with Inifile do

  try

    Splash:= ReadBool('ShowSplash','LastChoice', True );

    Checkbox1.Checked := Splash;

   if Splash then

   begin

     Sleep(1000);

     Form2.Close;

     Form2.Release;

   end;

  finally

    Free;

end;

end;



procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

var

   Splash: Boolean;

begin

  Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));

  Splash := Checkbox1.Checked;

  with Inifile do

     try

       WriteBool('ShowSplash','LastChoice', Splash);

     finally

   Free;

  end;

end;



end.

================================================================







Unit2.pas [Your splashscreen]

================================================================

unit Unit2;


interface


uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtCtrls, IniFiles;



type

  TForm2 = class(TForm)

  private

  public

  end;



var

  Form2: TForm2;

  Splash: Boolean;

  Inifile: TIniFile;



implementation



{$R *.dfm}



initialization



Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));

  with Inifile do

    try

      Splash:= ReadBool('ShowSplash','LastChoice', True);

     finally

      Free;

    end;

    if Splash then

      begin

        Form2 := TForm2.Create(nil);

        Form2.Show;

        Form2.Update;

      end;



end.



Easy SplashScreen Writing Guide by Fdehell  August 24th, 2006















Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
No response anymore?
    Nullified van Bommel (Jul 28 2010 3:12PM)

This is my own article, i created it years ago, but forgot the password, and now i do not get any reply anymore, while my previous domain had been shutdown, use the new url please

http://www.delphi7.nl/tutorials/splashscreen.php
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
R. Lefter
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)