A carefully written WINDOWS program displays startup precautions, called splash screen. Using a little bit of content, you can add a lot of color to the display of the program.
Since the project itself creates the main window of the program and the startup sputtering screen must appear before the main window is created, the project file must create its own startup screen. This means that the user must modify the source code to create the project file, which is usually not required in DELPHI programming. The following process introduces the process of setting up a sputtering screen.
1. Start a new project. Name the form MainForm and set its Caption property to SplashinDemo. Save this project in a directory, such as C: PRojectsSplashin. Name the mainForm unit Main and name the project file Splashin.
2. Insert a Button component in MainForm. Change the Name property of Button to ExitButton, and its Caption property to Exit. Create a processor for the OnClick event of ExitButton, inserting a Close statement between the begin and end keywords of the process.
3. Select the File|New Form command, or click the New Form speed button. Add a new form.
4. Change the Name property of this form to SplashForm and delete its Caption property. In addition, change its BorderStyle property to bsnone, and set the three subvalues under BorderIcons to False.
5. Save this project. When Delphi prompts the reader to provide the unit file name, be sure that the current directory is the correct directory. Enter Splash for the unit file name of SplashForm.
6. Set the Enabled property of SplashForm to False. This is one of the rare cases where users don’t want to provide keyboard and mouse commands to windows. In this example, we want the program to have full control over the display of SplashForm.
7. Since the window has no outline, insert a Bevel component object from the Additional component class. This helps define the edges of the window. Set the Align property of Bevel1 to alClient. At the same time, change the Shape property of the object to bsFrame and change its Style property to bsRaised. These values are determined by the user.
8. Insert the components you want to use in SplashForm, do not insert any buttons or other interactive controls here. The application itself displays and removes the Start Sputtering dialog box.
9. Select the Project menu. Highlight the Splash project pop-up menu. Select the Options command. In the generated Project Options dialog box, select the Forms page label. Note that MainForm and SplashForm are in the automatically created form list. Highlight each form and click the right mouse button to move it to the Available form. All Delphi forms are automatically created in memory at runtime, which consumes memory and system resources. In such a case, the program creates the form at runtime, and the reader should delete the form from the automatically created list. Close the ProjectOptions window.
10. Next, modify the project's source code to display the sputtering dialog box before displaying the main window. Here you need to insert statements in the project file to match the Splash.dpr project file. The project source code is as follows:
program Project3;
uses
Forms,
main in 'main.pas' {MainForm},
splash in 'splash.pas' {SplashForm};
{$R *.RES}
Begin
SplashForm:=TSplashForm.Create(application);
SplashForm.Show;
SplashForm.Update;
Application.CreateForm(TMainForm, MainForm);
SplashForm.Close;
Application.Run;
end.
11. If the program is compiled and run at this time, it will display and remove the start sputtering dialog very quickly, so that the user may not have the chance to see it. To force the dialog box to remain visible for a few seconds, select the program's MainForm. Create a processor for the OnCreate command of the form. Add a long integer variable called stopTime before the keyword. Insert two statements between begin and end: one is a call to the Windows GetTickCount function. Set stopTime to the number of seconds that Windows is running; another statement is the while statement, which delays another 2 seconds. The program list is as follows:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TMainForm = class(TForm)
Exitbutton: TButton;
procedure ExitbuttonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
Private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
Implementation
{$R *.DFM}
procedure TMainForm.ExitbuttonClick(Sender: TObject);
Begin
close;
end;
procedure TMainForm.FormCreate(Sender: TObject);
var
stopTime:LongInt;
Begin
stopTime:=GetTickCount div 1000;
while ((GetTickCount div 1000)<(stopTime+2)) do
Sleep(1);
end;
end.
12. Press F9 to compile and run the program.