Board index » delphi » TImageList/ TCustomListbox problems

TImageList/ TCustomListbox problems

I'm hoping someone can help me with this, as I've been stumped by it
for 3 days. Here's what I am trying to do:

I have a Paradox table that contains a BLOB Field which is used to
store a bitmap. There is also a text field. I write all of the
graphics to an ImageList, and all the text to a StringList. Then I use
Stream.WriteComponent to write the ImageList to a TMemoryStream and
send this stream. On the client end, I use the following code in the
Client.OnProcess event to try and get the imagelist off the stream,
and the images off the imagelist (the TextRepList is used for the text
field) :

Stream.ReadComponent( femoticonList )
pic := TBitmap.Create();
textRepList := TStringList.Create();
Stream.Read( numEmots, sizeOf( numEmots ) );
textRepList.LoadFromStream( Stream );
for count := 0 to (numEmots-1) do
  begin
    femoticonList.GetBitmap( count, pic );
    StringVal := textRepList.Strings[count];
    lbEmots.Items.AddObject( StringVal, pic );

My listbox is of type OwnerDrawFixed and I use the ListBox.DrawItem
event to draw the listbox. The problem is: Only the last image in the
table is being drawn (the correct # of times, beside each text line).
The text works fine. Any ideas anyone? Any help would be greatly
appreciated! Thanks.

 

Re:TImageList/ TCustomListbox problems


In article <20827855.0111260826.1ccc3...@posting.google.com>,

Quote
chelen...@hotmail.com (Chelene) writes:
>The problem is: Only the last image in the
>table is being drawn (the correct # of times, beside each text line).
>The text works fine. Any ideas anyone?

You have created ONE bitmap and continuously allocated each bitmap in the
stream to it and then added the bitmap to each object in the listbox. The
multiple references to one bitmap all refer to one image, which is shown
against all text items.

Code as follows ...

for count := 0 to (numEmots-1) do
  begin
    pic := TBitmap.Create();   // < < < < move this to here
    femoticonList.GetBitmap( count, pic );
    StringVal := textRepList.Strings[count];
    lbEmots.Items.AddObject( StringVal, pic );

Don't forget to free the bitmaps when you have finished with them <g>

Alan Lloyd
alangll...@aol.com

Other Threads