Search code examples
delphidelphi-2007imagelist

Image list usage


I store the icons for my applications inside several image lists.

Have one to:

X16

X24

X48

X32

Both TActions and direct access to place ICOs in a TButton, or TImage came from this several Image Lists.

My problem is that when I need to remove one its nightmare

I thought of setting a CONST value to everyone, but as some are used in TActions it’s not a complete solution.

How are you guys doing this and what solutions do you have to solve or at least improve this? I use DELPHI 2007.


Solution

  • What I do is add all the icons at runtime by loading from then from resources. When I add them I save the index of the added icon to a global variable. I also assign the ImageIndex property of each action at runtime by referring to these global variables.

    This allows flexibility to add and remove icons to the project without having numbering problems. The approach caters for runtime icon size decisions based on font scaling. The drawback is that you don't get to see the images at design time which is a drawback. If you want to have all the flexibility outlined above I don't see a better solution. In an ideal world the images would be identified by a name or an ID rather than a contiguous index into an array. But to achieve that you would need to implement a lot of code on top of the VCL.