Displaying splash screen in Delphi when main thread is busy

Harriv picture Harriv · Dec 23, 2008 · Viewed 11.6k times · Source

I'd like to display splash screen while the application is loading. However some 3rd party components block main thread during initilization for several seconds, which causes all forms not to update. Is it possible to have splash screen with own thread so it would update also when main thread is busy?

The application is win32 and Delphi version 2007.

Edit: I'm trying to avoid "undrawn splash screen" effect, which happens if some other windows (from other applications) are on the top of splash screen, eg alt-tabbing to another application and back.

Answer

mghie picture mghie · Dec 23, 2008

You can run the splash screen in another thread, but then you will need to use raw Windows API calls or a third-party library (like Key Objects Library) that implements VCL-like classes. Do however not access VCL stuff from splash thread.

If you go that route (which I don't think you should, as it is a lot of work for little gain), be sure to observe the rules about Windows API access from multiple threads. Google for example for "user interface threads" for more information.

Edit:

I wasn't aware of it before, but there is actually a component implementing a Threaded Splashscreen for Delphi on CodeCentral. Using this component it may (haven't tried it) actually be easy to have the splash screen in a different thread, but the warning against VCL access from secondary threads remains.