Unifix knowledge database - The original one

Dashboard - News - Search - List - About - Admin


Delphi: How to Add a Splash Screen to Your Application

Author:ino - Wed Jun 16 17:17:04 2004

From: http://info.borland.com/devsupport/delphi/devcorner/techtips/splash.html

Splash Screens are important to your applications. They provide function while adding to your application's visual appearance and interface. Splash Screens communicate with users of your application.

Using Splash Screens in your applications can uniquely distinguish yours from the others.

There are many types of Splash Screens. The most common Splash Screens are the ones you see when an application is first being loaded. These usually display the application's name, author, version, copyright, and image or icon that uniqely identifies it.

However, some applications use Splash Screens to display and notify the user of the progress of a time-consuming process. An example would be a SplashScreen that communicates the percentage of completetion of a databasetask, file task, or numeric processing tasks. The Progress Splash Screen offers users the courtesy of being informed.

You now see the benefits of Splash Screen. Let's show you how to create a simple one for yourself.

   1. Add a form to your project --> File | New Form.. Commentary: A Splash Screen is like any other form.
   2. Change the Name Property of the Form to SplashScreen
   3. Change the BorderStyle Property of the Form to bsNone
   4. Change the Position Property of the Form to poScreenCenter
   5. Customize your Splash Screen by adding various Components on the Form. (Labels, Panels, Images, Shapes, and Bevels)
   6. Edit the Properties of the added Components
   7. Select Options | Project from the Delphi IDE Menu
   8. Move the SplashScreen Form from the Auto-create listbox

      Commentary: You'll create a dynamic instance of the Splash Screen
   9. Add the unit containing TSplashScreen to the uses clause of your application's main form. Example:

          unit Unit1;             
          interface             
          uses SysUtils, WinTypes, WinProcs, Messages, Classes,                
               Graphics, Controls, Forms, Dialogs, StdCtrls,                
               unit2;  <---- put here

      Commentary: In this example, TSplashScreen has been declared in Unit2
  10. Select View | Project Source from the Delphi IDE Menu
  11. Add the following code after the begin statement and before any of the Application.Create() statements Code Addition:

          SplashScreen := TSplashScreen.Create(Application);              
          SplashScreen.Show;              
          SplashScreen.Refresh;

  12. Edit the OnShow event of your application's main form. Add the following code. Code Addition:

          SplashScreen.Free;

      Commentary: The implementation of a Progress Splash Screen is not much different than this example. The concept is that you create and show the splash screen before a process and free it after the process is completed. The difference is that you may want to talk back and forth between the process and the Splash Screen to update the progress.
  13. Run the Application. In this example, depending on the speed of your machine, you will barely see your new Splash Screen. You could add the following code to view your Splash Screen-- but we suggest that you use caution if you implement this technique in your application.

      Add this code immediately following the code addition in step #11 Code Addition:

         for x:= 1 to 10000000 do               
         begin                 
           x:=x;
         end;\

*************************************************
{PROJECT1.DPR}
program Project1;
uses
  Forms,
  Unit1 in 'UNIT1.PAS' {Form1},
  Unit2 in 'UNIT2.PAS' {SplashScreen};
{$R *.RES}
var
  x: longint;
begin
  SplashScreen:= TSplashScreen.Create(Application);
  SplashScreen.Show;
  SplashScreen.Refresh;;
  for x:= 1 to 10000000 do
  begin
    x:=x;
    x:=x;
  end;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
*************************************************
{UNIT1.PAS}
unit Unit1;
interface
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, unit2;
type
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormShow(Sender: TObject);
begin
  splashscreen.free;
end;
end.
*************************************************
{UNIT2.PAS}
unit Unit2;
interface
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ExtCtrls;
type
  TSplashScreen = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  SplashScreen: TSplashScreen;
implementation
{$R *.DFM}
end.
Copyright(c) Unifix.org 2002-2011


Dashboard - News - Search - List - About - Admin
 
Powered by Mikjaer Consulting Solutions - Hosted by Specialhosting.dk