Solved

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

Posted on 1998-08-28
6
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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!

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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