Create an animated splashscreen delphi 7

I am trying to create an animated pop-up screen while my application loads its database. I already created splashscreen, but I want the image to "move" from left to right when db is converted. I searched for a while, but all I could find was about progress bars ...

Here is my code:

SplashScreen := TSplashScreen.Create(Application) ; SplashScreen.Show; Application.Initialize; SplashScreen.Update; SplashScreen.lblStatus.Caption:='Loading...'; SplashScreen.Update; SplashScreen.lblStatus.Caption:='Updating database...'; SplashScreen.Update; Application.Initialize; Application.CreateForm(TfmMain, fmMain); Sleep(1000); Application.CreateForm(TfmPrefs, fmPrefs); Application.CreateForm(TfmCode, fmCode); Application.CreateForm(TfmEmps, fmEmps); Application.CreateForm(TfmRest, fmRest); Application.ShowMainForm:=FALSE; SplashScreen.Hide; SplashScreen.Free; Application.Run; 

In my splashscrren form, I created 5 duplicates of the same image, and when creating the main form, I want the image to be visible and invisible as an alternative ... ex:

 while my db loads... begin Splashscreen.Image1.Visible:=FALSE; SplashScreen.Update; Sleep(25); SplashScreen.Image1.Visible:=FALSE; SplashScreen.Update; SplashScreen.Image2.Visible:=TRUE;.... 

etc.

Any thoughts?

+4
source share
1 answer

Doing heavy work in the main thread during startup (for example, initializing a database and many forms) does not work with splash screens. The main thread is too busy to do anything with the GUI. Including sleep in the code will not work, as this will stop the main thread from doing any work at all.

This gives you two options:

  • Initialize the database in another thread. Sometimes also a good initialization of the main form. The database thread can send progress messages to the splash form via PostMessage calls.

  • Run the screensaver in a separate thread. This is quite complicated because you cannot use VCL from another thread. Also, you should avoid blocking the message queue. Fortunately, Peter Below made a good example of how to make a multi-user screensaver using only windows api calls.

There is additional information in this SO thread: displaying-splash-screen-in-delphi-when-main-thread-is-busy .

+4
source

Source: https://habr.com/ru/post/1381967/


All Articles