hyper66
asked on
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Sleep(5000);//This is in miliseconds
This will wait for 5 seconds
Regards,
Viktor Ivanov
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(Appli cation);
SplashScreen.Show;
SplashScreen.Update;
Application.Initialize;
Application.CreateForm(TFo rm1, 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.FormCloseQue ry(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.ProcessMessage s;
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.
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(Appli
SplashScreen.Show;
SplashScreen.Update;
Application.Initialize;
Application.CreateForm(TFo
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(
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.FormCloseQue
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.ProcessMessage
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.
ASKER
sorry i'll get back to you soon i've just been working overtime on night shift.
ASKER
Thank you everyone for your help. Hyper66.
{ 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;