Image of Navigational Map linked to Home / Contents / Search How to write Delphi Wizards

TSplashFormExpert
Image of Line Break

So far, we've seen and build our own Standard Experts and Project Experts. It isn't really hard to make a Standard Expert into a Project Expert. But what about the third kind of Expert; Form Experts? This one doesn't open up a file as a project, it usually creates something, a form and corresponding code. Remember the Dialog Expert and Database Form Expert? How do they work, and more important, can we do the same thing all by ourselves?
As a useful example of a Form Expert, I've come up with the idea of a Splash Form Expert. Every state-of-the-art application needs a Splash Screen, right? Why not automate the process and have a Splash Form Expert that generates one for us? All we need is a bitmap and a little border around it. If we want to, we can always make it more complex afterwards. First, let's look at what the resulting should look like. Just a plain form with a Panel and Bitmap should do it. Make sure the panel shows a nice border, and size the form enough to fit around the bitmap and panel (you don't want to resize/stretch the bitmap unless absolutely necessary, of course).
I found the most convenient way to add a Splash Screen to my application is to use the following technique. The unit below must be included in the uses clause of the main .DPR file, and will then get activated when the application starts (see the initialization part?). The FormDeactivate method will then make sure that this Splash Screen is shown right until the first main form comes up (and gets activated). At that time, the Splash Screen is freed. Note that this technique will only work for large, slow or database programs, i.e. programs that will take some seconds to show the main form. Otherwise, the Splash Screen will only flicker to be replaced almost immediately by the main form.

unit SplashFm;
interface
uses Forms, Classes, Controls, StdCtrls, ExtCtrls;

type
  TSplash = class(TForm)
    Panel1: TPanel;
    Image1: TImage;
    procedure FormDeactivate(Sender: TObject);
  end;

implementation
{$R *.DFM}

var
  Splash: TSplash;

procedure TSplash.FormDeactivate(Sender: TObject);
begin
  Screen.Cursor := crDefault;
  Splash.Free;
end;

initialization
  Screen.Cursor := crAppStart;
  Splash := TSplash.Create(nil);
  Splash.Show;
  Splash.Update
end.

Since the Panel is wrapped around the bitmap, and the Form is sized to fit around the Panel, all we need is an Wizard that enables us to select a bitmap from somewhere, and generates the code above with a corresponding .DFM form file.

Actually, the Splash Form Wizard is part of Dr.Bob's Collection of Delphi/C++Builder Wizards (and was used to generate the Splash Screen for the collection itself):


Image of Arrow linked to Next Article Image of Arrow linked to Next Article
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]