I'm trying to dynamically fill an ImageList with png icons stored in a database. Afterwards, that ImageList will be linked to an ImageComboBox and the icons displayed.
I'm sure the save and load from the database is working just fine, because I checked the temporary file created by the code below. However the problem is on adding images to the ImageList. After that cycle that keeps creating and adding Bitmaps to the ImageList I check the Count field and it has 0 items!!
What am I missing? What doesn't the ImageList.Add() properly work? I tried with and without a bitmap mask and got the same problem.
Delphi...
items.Clear; index := 0;
while not Eof do
begin
// Table (blob) to File
tmpIconFilename := FieldByName('IdIcon').AsString + '.png';
tmpIconFilepath := ExtractFilePath(Application.ExeName) + tmpIconFilename;
blobIcon := FieldByName('Icon32') as TBlobField;
blobIcon.SaveToFile(tmpIconFilepath);
// File to Stream
streamIcon := TMemoryStream.Create;
tmpFileIcon := TPngImage.Create;
tmpFileIcon.LoadFromFile(tmpIconFilename);
tmpFileIcon.SaveToStream(streamIcon);
DeleteFile(tmpIconFilename);
// Stream to Bitmap
bitmapIcon := TBitmap.Create;
bitmapIcon.LoadFromStream(streamIcon);
// Bitmap to ImageList
maskIcon := TBitmap.Create;
maskIcon.Assign(bitmapIcon);
maskIcon.Canvas.Brush.Color := clNone; //bkg color
maskIcon.Monochrome := true;
imagelistNotifPosIcon.Add(bitmapIcon, maskIcon);
// Add (icon) item to (icon) combobox
Item := Items.Add as TcxImageComboBoxItem;
Item.Value := FieldByName('IdIcon').AsString;
Item.Description := FieldByName('IdIcon').AsString;
Item.ImageIndex := index;
index := index + 1;
Next;
end;
ShowInfoMsg('ImageList count: ' + IntToStr(imagelistNotifPosIcon.Count));
Help is much appreciated.