TImageList.ShareImages-如何准确使用而不必复制内容? [英] TImageList.ShareImages - How to use exactly to not have to copy the content?
问题描述
我使用C ++ Builder,但是这个问题与我相信的Delphi同样重要。
I use C++ Builder, but the question is just as relevant for Delphi I believe.
当我有两个 TImageList $ c时$ c>对象,有时我想在两个图像列表中使用相同的图标,我可以复制内容:
ImageList2.Assign(ImageList1);
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) ;
但是,我在帮助中注意到 TImageList.ShareImages
提示我可以使用相同的内部列表,并节省复制资源!但是记录不佳,因为我不确定如何才能做到这一点?
如何使 ImageList2
使用与 ImageList1
相同的内部列表? (然后,我会设置 ImageList2.ShareImages = true
。
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.
推荐答案
As我阅读了源代码,您是这样做的:
As I read the source code, you do it like this:
ImageList2->Handle = ImageList1->Handle;
ImageList2->ShareImages = true;
所有 ShareImages
控件是图像列表句柄是否为列表所有者,在这种情况下,它由 ImageList1
拥有,而不是 ImageList2
。
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
.
其结果是, ImageList1
必须退出 ImageList2
;否则,如果首先销毁 ImageList1
,则将保留 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.
这篇关于TImageList.ShareImages-如何准确使用而不必复制内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!