In this example, two problems are tested:
1. Can images loaded by other VCL be used by tdximagelist;
2. Can images in tdximagelist be used by other VCL instances.
In this example, the image is first loaded with tpicture and then added to tdximagelist;
Then draw the image on the form, instead of in tdxdraw.
Learn more about tdximagelist:
The tdximagelist control has only two attributes: dxdraw and items.
Dxdraw is the destination of the image, which is easy to understand;
Items is a collection of objects: tpicturecollection;
The tpicturecollection collection contains a set of tpicturecollectionitem objects;
The tpicturecollectionitem object has the picture attribute, which is compatible with tpicture in other VCL!
In this example, the tpicturecollectionitem object is used to test:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, dxdraws, stdctrls; Type tform1 = Class (tform) dximagelist1: bytes; button1: tbutton; button2: tbutton; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} {borrow other VCL controls to load images} procedure tform1.formcreate (Sender: tobject); var PIC: tpicture; begin PIC: = tpicture. create; pic. loadfromfile ('C: \ temp \ test.bmp '); dximagelist1.items. add; dximagelist1.items [0]. picture. assign (PIC); pic. free; end; {This code looks simple, but the code prompts are not good} procedure tform1.button1click (Sender: tobject); Begin self. refresh; self. canvas. draw (0, 0, dximagelist1.items [0]. picture. graphic); end; {use the tpicturecollectionitem object to transfer and write it smoothly} procedure tform1.button2click (Sender: tobject); var picitem: tpicturecollectionitem; Begin self. refresh; picitem: = dximagelist1.items [0]; self. canvas. stretchdraw (clientrect, picitem. picture. graphic); end.