How do I merge TMainMenu's that use separate imagelists and retain the correct images by each menu item?

StackOverflow https://stackoverflow.com/questions/152405

  •  02-07-2019
  •  | 
  •  

Question

I have a program with two TForm classes and have added a TMainMenu to them each. I am then trying to merge them dynamically at run-time.

My problem is that when they merge the menu items in the merged in TMainMenu now display images stored in the imagelist in the form they were merged into rather than the images stored in their original form's imagelist.

Am I doing something wrong? is there a work around so that the menu item's continue to use the imagelist in the form they originated from?

I use the merged-in form in a number of projects, otherwise a single shared imagelist would make sense.

If I need to clarify anything, please say.

Thanks

Peter

Was it helpful?

Solution

The way I handle this is to have a single image list on a datamodule, and then include that in each form so that they can share that single set of icons.

OTHER TIPS

I had exactly the same problem a while ago, but I also ran into other menu merge problems because my app was MDI, so I decided to do things in a completely different way.

What you could try, though, is dynamically adding one form's images to the other form's ImageList, and 'redirecting' the ImageIndexes. Might be a bit tricky, but should work.

What I eventually ended up with, is using the Toolbar2000 package for all my menus and toolbars. You can then download a very nice piece of code, called TB2Merge, which does exactly what you want. It also makes use of some of Toolbar2000's infrastructure to link a menu item's image to a different TImageList --- infrastructure that is not present in the VCL's TMainMenu. Be sure to read TB2Merge's documentation thoroughly!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top