Re: bitmaps in TListbox reappear

besh_at_cix.compulink.co.uk
Date: 03/29/05


Date: Tue, 29 Mar 2005 14:23:02 -0600


> What does your OnDrawItem event look like?

Here's the full proc

procedure TForm1.ListBox3DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
    Bitmap: TBitmap;
begin
    with (Control as TListBox).Canvas do
    begin
      try
      FillRect(Rect);
      Bitmap := getmodimage( strtoint(getitemdata(inttostr(index), '4')),
                             getfbbx(1), inttostr(index), 1);
      if Bitmap <> nil then
      begin
        BrushCopy(Bounds(Rect.Left + 2, Rect.Top, Bitmap.Width,
            Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
            Bitmap.Height), clRed);
      end;
      finally
      bitmap.free
      end;
    end;
end;

getmodimage is a function that returns a TBitmap;

function GetModImage(wid, heit:integer;charval: string; sze:integer):
TBitmap;

showing the bitmap creation part
    result := Tbitmap.create;
    result.width := wid;
    result.height := heit;
    result.monochrome := true;
    result.pixelformat := pfDevice; //changed to pfdevice from pf1bit
    
    the rest is just bitmap drawing routines.
    
    Since Result is a TBitmap, it cannot be freed within the function.
However the bitmap is freed in the OnDrawItem procedure.

The code works beautifylly, but for the listbox items not 'refreshing'.

Neil



Relevant Pages

  • Re: TImage vs TBitmap Verwirrung
    ... TPicture hat eine Eigenschaft Bitmap mit der man sich eine Bitmap ... TBitmap in Picture.Graphic steckte. ... Dir dieser Canvas das Malen erlaubt - siehe oben, es kann ... Leite eine neue Komponente von TGraphicControl oder TWinControl ab, ...
    (de.comp.lang.delphi.misc)
  • Re: Please make a new AutoVar Statement
    ... Bitmap: TBitmap; ... in your tbitmap example you'd still ... need to set the bitmap's size, pixel format, load it from a file, etc. So ... programmer has to keep track of when reading through someone else's code. ...
    (borland.public.delphi.non-technical)
  • Re: wo hier den Destructor platzieren
    ... Es ging mir ja um die Funktion vom Typ TBitmap mit dem Namen Real2Bitmap. ... Das bitmap das du in der Function Real2Bitmap erzeugst, ... Var fQuellBitmap: TBitmap; ...
    (de.comp.lang.delphi.misc)
  • Re: ownerdrawing (on a components canvas): comitting any sins here?
    ... R: TRect; s1: string; s2: string; BM: TBitmap; BM2: TBitmap; begin ... BM2:= TBitmap.create; ... this means that you have created a blank bitmap and then have the object pointer replaced by another bitmap that was created from the ...
    (alt.comp.lang.borland-delphi)
  • Re: ownerdrawing (on a components canvas): comitting any sins here?
    ... If I don't create the Bitmap then the Bitmap is not drawn and ... BM is Nil, but it does not seem to return a Bitmap ... GetBitmap does not take a "var" parameter, which means that the BM parameter needs to refer to a valid TBitmap instance before you call GetBitmap. ... you don't need to use the VAR on it, the pointer address gets past to the stack. ...
    (alt.comp.lang.borland-delphi)