Solved

How do i make a splash screen delay for a period of time

Posted on 1998-08-28
6
395 Views
Last Modified: 2010-05-18
How do i make a splash screen delay for a period of time that i chose to. like 10 seconds. Examples please.
0
Comment
Question by:hyper66
6 Comments
 
LVL 2

Accepted Solution

by:
kjteng earned 50 total points
Comment Utility
Put the following code in an appropriate place of you code:
( t1 is a variable of longint)

  t1:= GetTickCount;
  repeat
  until  GetTickCount - t1  > 10000;
0
 
LVL 2

Expert Comment

by:kjteng
Comment Utility

 { put this before you show the splashscreen,
   GetTick is a WinAPI }

  t1:= GetTickCount;

 { put this before you free the splashscreen}
  repeat
  until  GetTickCount - t1  > 10000;


0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
You could also use this instead of writing all that code....

Sleep(5000);//This is in miliseconds

This will wait for 5 seconds

Regards,
Viktor Ivanov
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Expert Comment

by:BlackDeath
Comment Utility
Hi, Hyper!

this one's from UNDU:
~~~~~~~~~~~~~~~~~~~~~

First, add a new form to your project. Name the form SplashScreen, and save the unit as SPLASH.PAS. Set the Form's BorderStyle to bsNone. Next, drop a TPanel on the Form, set it's Align property to alAlignClient and set its Bevel and BorderStyle properties however you wish. Lastly, drop a TImage on the form and set it's Align property also to alAlignClient. Then Load the TImage with your graphic.

To make the splash screen appear when the application launches, you need to modify your application source code (the DPR file). Go to the View menu and pick Project Source. Make the following revisions to cause the Splash Screen to appear before the first form.

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Splash in 'Splash.pas' {SplashScreen};

{$R *.RES}

begin
  try
    SplashScreen := TSplashScreen.Create(Application);
    SplashScreen.Show;
    SplashScreen.Update;
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
    SplashScreen.Close;
  finally
    SplashScreen.Free;
  end;
  Application.Run;

end.

and this is also from UNDU:
~~~~~~~~~~~~~~~~~~~~~~~~~~~

The purpose of a SplashScreen is twofold. It's primary purpose is to announce your application, version number, etc. The second is to conceal the delay required for the rest of your application to complete loading and to appear on the screen.
Ideally, a SplashScreen should appear immediately when the user clicks the application icon, and not disappear until the main form of the app is on the screen and ready to accept input. Now, there isn't much we can do to control how fast it appears… we have it appearing as quickly as it can because it is in the project file and is loading before any other part of the program.

However, what if your application only takes a second or two to load, but you still want a splash screen. With the solution provided before, the SplashScreen would appear and disappear too rapidly.
Hence this modification to implement a minimum amount of time that the SplashScreen should stay on the screen. It is quite simple actually, just take the code from the prior article on creating a SplashScreen, and add a timer to the SplashScreen form. Set its interval to 1000 times the number of seconds you want the form to be visible (3-4 seconds is good, so a value of 3000-4000 would be ideal). Make sure it's Enabled value is True. Then double-click on the Timer's OnTimer event and add the following code:

    procedure TSplashScreen.Timer1Timer(Sender: TObject);
    begin
      Timer1.Enabled := False;
    end;


Lastly, go back to the form in the object inspector and double-click on the OnCloseQuery event. Add the following code:

    procedure TSplashScreen.FormCloseQuery(Sender: TObject;
                         var CanClose: Boolean);
    begin
      CanClose := Not Timer1.Enabled;
    end;


Here is what this does: First, since the timer is enabled initially, it will start counting once the form is created. Once the timer expires its first time, it is disabled. As a result, it will only run once through its interval and then stop. The OnCloseQuery event is used to tell Windows whether the form can be closed or not. If the CanClose variable returns True, the form will be allowed to close, and if it returns False, it won't be. All we have to do is return the opposite of the Timer's Enabled state. If the timer is still running through its first delay, don't allow the form to close yet. As soon as the timer is done, it will be disabled, which will allow the form to close.

The last thing we have to do is modify the project code just a bit to pay attention to the CloseQuery property. Add the following code just before the SplashScreen.Close command in the project source:

    repeat
      Application.ProcessMessages;
    until SplashScreen.CloseQuery;


When the application gets to this point, it will stay in this repeat loop until the SplashScreen's CloseQuery call permits it to continue. If your application takes longer to load then the SplashScreen's delay setting, then the SplashScreen will close immediately when it gets to this point.

if this isn't it, i'm sorry,

regards,
Black Death.
0
 

Author Comment

by:hyper66
Comment Utility
sorry i'll get back to you soon i've just been working overtime on night shift.
0
 

Author Comment

by:hyper66
Comment Utility
Thank you everyone for your help. Hyper66.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now