Solved

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

Posted on 1998-08-28
6
407 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
ID: 1338045
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
ID: 1338046

 { 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
ID: 1338047
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Expert Comment

by:BlackDeath
ID: 1338048
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
ID: 1338049
sorry i'll get back to you soon i've just been working overtime on night shift.
0
 

Author Comment

by:hyper66
ID: 1338050
Thank you everyone for your help. Hyper66.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 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