How to refresh/repaint Canvas with InvalidateRect?


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);
   FZoom := AZoom;

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

procedure TFBRA.CurveBoxPaint(Sender: TObject);

procedure TCurveCtrl.DrawCurves;
   Points: array of TPoint;
   {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

Andreas Olsson