SpashScreen with ProgressBar

Hi again,

I have an application which has quite a few things to load at the beginner so I'm going to add a splash screen to it.
My question is: How do I make a splashscreen with a progressbar on it?

Thanks

ST3VO
ST3VOAsked:
Who is Participating?
 
JohnjcesCommented:
I do all of my splash screen stuff in my .dpr file... the Delphi project file.

I create the splash screen, show and update it, then create my other forms, which may initialize "stuff" when  created,  (OnCreate event) delay the action so the progress bar doesn't move too quickly and then show my main form and close the splash screen. (Not all the forms listed are created at run time as some are created when needed and then freed).

Here is the dpr file.

program HonDahPMS;

uses
  Forms,
  Pers in 'Pers.pas' {FPersonnel},
  FindEmp in 'FindEmp.pas' {FFind},
  PayrollEffDate in 'PayrollEffDate.pas' {FPayrollEffDate},
  Logon in 'Logon.pas' {FLogon},
  Crypt32 in 'Crypt32.pas',
  Permissions in 'Permissions.pas' {FPermissions},
  DatCalc in 'DatCalc.pas' {FDateCalc},
  SQLChk in 'SQLChk.pas' {FSQLCheck},
  DBInfoCode in 'DBInfoCode.pas' {FDBInfo},
  backupdb in 'backupdb.pas' {FBackUp},
  restoredb in 'Restoredb.pas' {FRestore},
  about in 'about.pas' {AboutBox},
  AnnLvLiab in 'AnnLvLiab.pas' {FAnnLvLiab},
  errorform in 'errorform.pas' {FErrorForm},
  FutureLeave in 'FutureLeave.pas' {FFutureLv},
  PickLists in 'PickLists.pas' {FPickLists},
  TribalRep in 'TribalRep.pas' {FTribalRpt},
  PersSummary in 'PersSummary.pas' {FPersSummary},
  copychartclp in 'copychartclp.pas' {FCopyChartClp},
  TrainSum in 'TrainSum.pas' {FTrainSum},
  Splash in 'Splash.pas' {FSplash},
  Closing in 'Closing.pas' {FClosing},
  Attend in 'Attend.pas' {FAttendance},
  AnnivReport in 'AnnivReport.pas' {FAnnivReport},
  MIS in 'MIS.pas' {FMISInfo},
  ListEmp in 'ListEmp.pas' {FListEmp},
  RandList in 'RandList.pas' {FRandList},
  Relative in 'Relative.pas' {FRelatives},
  SingleBCMain in 'SingleBCMain.pas' {FSingleBC},
  BarCodeMain in 'BarCodeMain.pas' {FBarcode},
  Recog in 'Recog.pas' {FRecognition},
  EmpSignInOut in 'EmpSignInOut.pas' {FSignInOut},
  SvcErrors in 'SvcErrors.pas' {FSvcErrors};

{$R *.RES}

begin
 FSplash := TFSplash.Create(Application);
 FSplash.Show;
 FSplash.Update;

// FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Main Form';
 Application.ProcessMessages;
 FSplash.Delay(750);
 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Connecting to SQL Server';
 Application.ProcessMessages;

 Application.Initialize;
// FSplash.ProgressBar1.StepIt;
 Application.Title := 'HonDahPMS';
 Application.CreateForm(TFPersonnel, FPersonnel);

  //Application.CreateForm(TFSvcErrors, FSvcErrors);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Form Find';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFFind, FFind);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Form Payroll';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFPayrollEffDate, FPayrollEffDate);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Form Logon';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFLogon, FLogon);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Form Permissions';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFPermissions, FPermissions);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating ErrorForm';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFErrorForm, FErrorForm);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Form FutureLv';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFFutureLv, FFutureLv);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Form Relatives';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFRelatives, FRelatives);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Form SingleBC';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFSingleBC, FSingleBC);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Form Barcode';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFBarcode, FBarcode);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Creating Form Recognition';
 Application.ProcessMessages;
 FSplash.Delay(100);

  Application.CreateForm(TFRecognition, FRecognition);

 FSplash.Label5.Caption := 'Creating Sign In/Out Log Date Set';
 FSplash.ProgressBar1.StepIt;
 Application.ProcessMessages;
 FSplash.Delay(100);

 Application.CreateForm(TFSignInOut, FSignInOut);

 FSplash.ProgressBar1.StepIt;
 FSplash.Label5.Caption := 'Finished Creating Forms!';
 Application.ProcessMessages;
 FSplash.Delay(200);

  Application.Run;
end.

Now my delay routine is in the FSplash form.

Procedure TFSplash.Delay(MSecs: Cardinal);
var
 FirstTick, CurrentTick : Cardinal;
 Done : Boolean;
begin
 Done := FALSE;
 FirstTick := GetTickCount;
 While Not Done do
  begin
   Application.ProcessMessages;
   CurrentTick := GetTickCount;
   If Int64(CurrentTick) - Int64(FirstTick) < 0 Then
    begin
     If CurrentTick >= (Int64(FirstTick) - High(Cardinal) + MSecs) Then
      Done := TRUE;
       End
        Else
         If CurrentTick - FirstTick >= MSecs Then
          Done := TRUE;
  end;
end;

I also change the mouse cursor during the splash screen presentation in the Form show and return it to default in the Form hide portion of the Splash Screen.

procedure TFSplash.FormShow(Sender: TObject);
begin
 Screen.Cursor := crAppStart;
end;

procedure TFSplash.FormHide(Sender: TObject);
begin
 Screen.Cursor := crDefault;
end;

Lastly, in my main form in the OnShow, I hide then close the Splash Screen and show my logon prompt.

procedure TFPersonnel.FormShow(Sender: TObject);
begin
 FSplash.Hide;
 FSplash.Close;
 FLogon.Show;
end;

A lot of steps, but makes for a pretty good splash screen with a progress bar. There are other ways and in another app I do everything in the FSplash. Load all of the other forms etc and have the the DPR only load and creaet the Splash Screen.

There are a lot of ways to do it, but the main thing is to create and show your spalsh screen in your dpr.

I hope this helped you out and gave you a good starting point.

John
0
 
Tomas Helgi JohannssonCommented:
  Hi!

This is just matter of creating a simple form with the desired info/image etc displayed on it
while loading.
Simple follow this example : http://www.swissdelphicenter.ch/torry/showcode.php?id=420
Then add the ProgressBar on the SplashForm and update it according to the load of your
application.

Regards,
   Tomas Helgi
0
 
ST3VOAuthor Commented:
Perfect. Thanks!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.