Skip to content

Tree lines not painted #1222

@pyscripter

Description

@pyscripter

As per title. Can be reproduced with the Advanced demo. If you set ReportMemoryLeaksOnShutdown to True you also get a memory leak.

Compare DrawDottedVLine and DrawDottedHLine

procedure TBaseVirtualTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension);

// Draws a horizontal line with alternating pixels (this style is not supported for pens under Win9x).

var
  R: TRect;

begin
  R := Rect(Left, Min(Top, Bottom), Left + 1, Max(Top, Bottom) + 1);
  with PaintInfo, Canvas do
  begin
    Brush.Color := FColors.BackGroundColor;
    Winapi.Windows.FillRect(Handle, R, DottedBrushTreeLines.Handle);
  end;
end;

procedure TBaseVirtualTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension);

// Draws a horizontal line with alternating pixels (this style is not supported for pens under Win9x).

var
  R: TRect;

begin
  with PaintInfo do
  begin
    DottedBrushTreeLines.Handle := FColors.BackGroundColor;
    R := Rect(Min(Left, Right), Top, Max(Left, Right) + 1, Top + 1);
    Winapi.Windows.FillRect(PaintInfo.Canvas.Handle, R, DottedBrushTreeLines.Handle);
  end;
end;

DottedBrushTreeLines.Handle := FColors.BackGroundColor makes the brush to paint solid lines at the background color and therefore non-visible. Note also that this statement leaks the TBitmap assigned to the brush.

Shouldn't DrawDottedHLine be similar to DrawDottedVLine ? If I change DrawDottedHLine to:

procedure TBaseVirtualTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension);

// Draws a horizontal line with alternating pixels (this style is not supported for pens under Win9x).

var
  R: TRect;

begin
  with PaintInfo, Canvas do
  begin
    Brush.Color := FColors.BackGroundColor;
    R := Rect(Min(Left, Right), Top, Max(Left, Right) + 1, Top + 1);
    Winapi.Windows.FillRect(PaintInfo.Canvas.Handle, R, DottedBrushTreeLines.Handle);
  end;
end;

then lines are drawn as expected.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions