views:

610

answers:

2

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

+7  A: 

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.

mj2008
My problem with this solution is that I include the second form in a number of different projects as an embedded form
Then move them to the main imagelist and change the imageindex accordingly.
Lars Truijens
+2  A: 

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!

onnodb