1

I have a TDatamodule that has a TImageCollection (70 images) and 3 TVirtualImageLists.
Its creation take a lot of time. The .dfm file measures slightly over 400 kB.

I'd like to autocreate this datamodule because the images are used throughout the program. But in the project source the Application.CreateForm(TDMImageStore, DMImageStore); takes 7-8 seconds (inside/outside the IDE).
Creating the datamodule later only moves the problem in time.

I assume this is all main thread code, any attempts to make a splash screen with an animation therefore fail.

Is there a way to work around this, e.g. create the datamodule in the background?
On program start the user lands in a menu screen which does not need the images yet, so there is some time for this (e.g. no actions requiring the images until a 'created' flag is set).

Win32 program in Delphi 10.4 Sydney.

(If there is no real way around this I can fall back on a static splash screen with an image.)

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
  • How are you loading the images? – sddk Feb 20 '21 at 14:28
  • I doubt you will succeed with the standard DFM streaming, because the underlying mechanism makes heavy use of global variables and objects. – Uwe Raabe Feb 20 '21 at 15:10
  • What I'll say here after could require a lot of changes in your application design depending on the use you do of the images. A way to speedup image access is either to build a large combining all the images or load each image individually as needed, caching them in memory. A 400KB large image should load in a fraction of a second. Then once loaded, you can, on demand, extract part of that large image into the originals ones in individual TBitMap. – fpiette Feb 20 '21 at 15:56
  • 1
    @UweRaabe DFM streaming alone should be threadsafe because it is protected by locks. Whether or not streaming TImageCollection and TVirtualImageList is thread safe that is another questions. – Dalija Prasnikar Feb 20 '21 at 16:07
  • 2
    Seems to go against suggested best practices; "A TVirtualImageList should always be placed on a form, not a data module. Forms have an associated monitor and DPI; data modules do not. A TImageCollection can be placed anywhere, since they are simply the source, and are unaffected by DPI changes: they are the source, while the virtual image list is the presentation." I would review what you are doing as 7-8 seconds is an extremly long to process 400KB of data. – Brian Feb 20 '21 at 16:07
  • @sddk They are present at design time, I later lookup up a bitmap by name and assign that to a TImage – Jan Doggen Feb 20 '21 at 16:20
  • @Brian, yeah this is NOT designed to support multiple monitors with different DPIs. I suspect the VirtualImageList – Jan Doggen Feb 20 '21 at 16:21

0 Answers0