procedure TfrmMain.lbLibDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var i, l, t, r, b, w, h, s, idx, w2: integer; cvs: TCanvas; found: boolean;
begin
  if Icons[Index] = nil then Exit;  cvs := TListBox(Control).Canvas;
  cvs.Brush.Color := clWhite;
  cvs.FillRect(Rect);
  cvs.Pen.Color := $DBBCBC;  l := Rect.Left + 1;
  t := Rect.Top + 1;
  r := Rect.Right - 1;
  b := Rect.Bottom - 1;
  w := r - l;
  h := b - t;  if (odSelected in State) then
  begin
    cvs.Brush.Color := $DBBCBC;
    cvs.RoundRect(l, t, r, b, 5, 5);
  end;  found := False;
  for i := 0 to Icons[Index].Images.Count - 1 do
  begin
    if Icons[Index].Images[i].Style = IconViewStyle then
    begin
      s := SIZES[IconViewStyle];
      Icons[Index].Images[i].Draw(cvs, l + (w - s) div 2, t + (h - s) div 2);//after this system DrawFocusRect is incorrect???
      found := True;
      Break;
    end;
  end;  // IconViewStyle not found, draw a symbol
  if not found then cvs.RoundRect(l, t, r, b, 5, 5);  if (not found) and Cfg['ColorCompatible'] then
  begin
    s := 0;    for i := 0 to Icons[Index].Images.Count - 1 do
    begin
      if 32 = Icons[Index].Images[i].Info.BitCount then
      begin
        w2 := Icons[Index].Images[i].Info.Width;
        if (w2 > s) and (w2 < SIZES[IconViewStyle]) then
        begin
          s := w2;
          idx := i;
        end;
      end;
    end;    if s > 0 then Icons[Index].Images[idx].Draw(cvs, l + (w - s) div 2, t + (h - s) div 2);
  end;
end;

解决方案 »

  1.   

    s := SIZES[IconViewStyle];//会不会是这个变量没释放呢?
      

  2.   

    Cfg['ColorCompatible'] 是什么?是自己写的一个类吗?
    Icons呢?
    是否在使用这些类的代码中某些资源没有释放?
      

  3.   

    应该和这些没关系,我都测试过了。应该是此函数中的图形相关资源没释放,canvas, pen之类。我很少自绘,所以对canvas应用不是很熟悉,使用canvas等图形相关对象后需要进行啥处理吗?
      

  4.   

    Canvas应该不需要特殊的释放处理。
    我还是认为是你自己写的类的问题。
    如果找不到原因,试着先屏蔽该函数中所有代码,然后一行一行地调试,看看究竟是哪一行引起的内存泄露。