The Unofficial Newsletter of Delphi Users - by Robert Vivrette



Here Thar Be Dragons!

by Clinton R. Johnson - xepol@poboxes.com

Every once in a while, you run across a feature in Delphi that just seems to cause problems.  One such example is the TImageList common control.

True, TImageList IS low on resources, but it comes at a cost: all your images in the TImageList must be of the same dimension.  This is because behind the screens, the TImageList creates a common bitmap.  The common bitmap is allocated with a fixed width (wide enough for 4 images) that can hold a certain number of images tiled vertically.  To add more images to the list, the common bitmap is made longer.  It seems innocent, but several problems appear.

We should all remember the problems that an number of Win3.1 drivers had with large bitmaps?  You can bet that corners were cut on the 95 drivers too.  Lets face it, it is unlikely that the driver designers decided to support a 100,000 scan line bitmap no matter how narrow.  You may get lucky, or you may get a buggy driver.  (I've already run into this problem using large 16 colour images, so it is still haunting us!)

Palettes? (read 256 colour images) FORGET IT!  Palettes just aren't supported.  You can't really blame Borland, the documentation does refer to the ability to assign a palette to the common bitmap, but never gets around to mentioning how.  Even if you could assign the common palette, all your images would have to use the common palette to work correctly.

Borland avoids the whole problem by mapping 256 colour images down to 16 colours. True,  High Colour and True Colour images(16 bits or higher) don't need palettes, but in 16 and 256 colour modes, the images are mapped down to 16 colours again.

Delphi 3's implementation does not support unmasked bitmaps correctly.  You can test this by setting the TImageListÆs MASKED property to False.  You can not save the form.  Internally, a second common bitmap is conditionally created based on the MASKED property.  It is a monochrome bitmap that stores the mask used when drawing.  The source of the problem is that the TImageList component ALWAYS expects the mask bitmap to exist when saving to a stream.  This prevents the form from saving or closing in the IDE.  The only work around is in the custom property editor.  When you load your images into the TImageList, you need to change what it selects as the transparent colour to one not used in the image.

I could go on for pages and pages about the problems related to this control, but I think you get the point.  The only condition I would recommend using the TImageList is when you need 16 colour images with transparency, otherwise you would be best advised to avoid it entirely.