?
Solved

SpashScreen with ProgressBar

Posted on 2007-09-28
3
Medium Priority
?
378 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:ST3VO
3 Comments
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 19978506
  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
 
LVL 18

Accepted Solution

by:
Johnjces earned 2000 total points
ID: 19978979
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
 

Author Comment

by:ST3VO
ID: 19979085
Perfect. Thanks!!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question