views:

182

answers:

2

In Delphi 2007, images are loaded in a TImageList at design time. This introduces the following problem:

  • I have a folder containing the graphics I'm using in my application
  • Whenever I want to change, say, the icon for 'save', I have to
    1. Change the graphic in the folder (for my own purposes)
    2. Iterate along all TImageLists in the application
    3. Change the graphic in the TImageList

Is there any way (component, compile script, ...) to perform steps 2 and 3 automatically, that is, specify only paths of graphics at design time, creating a dependence on the actual graphic files?

+1  A: 

Classes are never fully compiletime. Designtime classes are streamed from resources too.

Marco van de Voort
OK, maybe I was too strict with 'at compile time'. I've edited the question.
Martijn
+2  A: 

You could create a descendant of TImageList and add that kind of logic there.

Since components referring to images inside a TImageList do that by index, it would be easiest to have your descendant to have a ImagePaths property of type TStrings that is formatted like this:

#=Filename

And maybe add a property BasePath of type string as well.

Then upon loading that component, it could automagically reload those images in memory.

You could even make it a design-time expert which loads the images in the designer.

--jeroen

Jeroen Pluimers
This is what I was thinking about. I was kind of hoping somebody did this already (lazy as I am...), since I'm not really an expert with the VCL.
Martijn
I don't know of anybody having done this already. You could be the first! ;-)
Jeroen Pluimers
Haven't really got time to do this right now, but it sounds like a nice project for in the future.
Martijn