TImageList.ShareImages - How to use exactly to not have to copy the content?

耗尽温柔 提交于 2019-12-13 02:38:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!