How to refresh/repaint Canvas with InvalidateRect?

Hello!!!

I'm drawing some curves and a grid with dotted lines on the TCanvas in a
TPaintBox object. The PaintBox is aligned inside a TPanel. I have created an
object (TCurveCtrl) to handle the curves and the grid. Sometimes I want to
erase the whole box and paint new curves and grid  (e.g. zoom), and sometimes
I just want to fill in some 'holes' in the Canvas without the image to flicker

(paint without erase).

I expected the following code to work but it didn't. When I want to update
the window, I call PaintCurves which triggs a CurveBoxPaint Event and calls
DrawCurves, which do the actual drawing. I have two problems with this code:

1. If I don't include the SendMessage part in DrawCurves, the background of
the dotted lines (PaintGrid) becomes white instead of clBtnFace even
though the Canvas brush and the Panels color property are set to clBtnFace.

2. It doesn't matter if Erase is True or False, the whole image is erased
anyway, making the screen to flicker when I, in some cases, want to redraw the

Canvas frequently.

I would really appreciate if someone had any suggestions what to do.

procedure TCurveCtrl.SetZoom(AZoom: TZoom);
begin
   FZoom := AZoom;
   PaintCurves(True);
end;

procedure TCurveCtrl.PaintCurves(Erase: Boolean);
begin
   InvalidateRect(FCurveBox.Parent.Handle, nil, Erase);
   UpdateWindow(FCurveBox.Parent.Handle);
end;

procedure TFBRA.CurveBoxPaint(Sender: TObject);
begin
   CurveCtrl.DrawCurves;
end;

procedure TCurveCtrl.DrawCurves;
var
   Points: array of TPoint;
begin
   {Don't want this, but if not added, the dotted lines
    background becomes white instead of clBtnFace}  
   SendMessage(FCurveBox.Parent.Handle, WM_ERASEBKGND,
                         CurveBox.Canvas.Handle, 0);
   PaintGrid;  //Painting the dotted lines
   ...

   FCurveBox.Canvas.PolyLine(Points);  //Painting the curves
end;

Andreas Olsson
cie95...@lustudat.student.lu.se