Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 499
  • Last Modified:

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

How do i make a splash screen delay for a period of time that i chose to. like 10 seconds. Examples please.
0
hyper66
Asked:
hyper66
1 Solution
 
kjtengCommented:
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
 
kjtengCommented:

 { 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
 
viktornetCommented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
BlackDeathCommented:
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
 
hyper66Author Commented:
sorry i'll get back to you soon i've just been working overtime on night shift.
0
 
hyper66Author Commented:
Thank you everyone for your help. Hyper66.
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.

Join & Write a Comment

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now