问题
I use C++ Builder, but the question is just as relevant for Delphi I believe.
When I have two TImageList objects and at some point I want to use the same icons in both image lists, I can copy the content: ImageList2.Assign(ImageList1) ;
However, I noticed TImageList.ShareImages in Help suggesting I can use the same internal list, and save resources copying !? Poorly documented however because I'm not sure how I can achieve this exactly ?
What do I do to make ImageList2 use the same internal list as ImageList1 ? (I would set ImageList2.ShareImages = true then.
回答1:
As I read the source code, you do it like this:
ImageList2->Handle = ImageList1->Handle;
ImageList2->ShareImages = true;
All that ShareImages controls is whether or not the image list handle is owner by the list. In this case it is owned by ImageList1 and not by ImageList2.
A consequence of this is that ImageList1 must out live ImageList2. Otherwise if ImageList1 is destroyed first, then ImageList2 is left holding on to a handle of an image list that has been destroyed.
来源:https://stackoverflow.com/questions/35081808/timagelist-shareimages-how-to-use-exactly-to-not-have-to-copy-the-content