Animation/Double Buffering Graphics

I am trying to create flicker free graphics in Delphi.  The routines I am using in C++ with the Windows API
calls don't seem to work for Delphi.  Included below is what I use in Borland C++ 3.1.

What happens if I don't call invalidate in WMPaint is that every other frame in the animation is filled with
garbage.  The InvalidateRect calls seems to fill the MemBmp with the contents of the previous frame or
something like that.  Anyway, it works.

In Delphi if I duplicate this logic without the Invalidate call I get the same as C++, every other frame filled
with garbage.  If I do include the Invalidate call, it recursively calls Paint (which seems to make more sense
than the C++ method.

Does anyone have example code to do double buffered graphics in Delphi or can explain whats going on
with this code?

void DrawWindow::WMPaint(RTMessage msg)
{
        InvalidateRect (HWindow, NULL, FALSE);
        TWindow::WMPaint (msg);

Quote
}

void DrawWindow::Paint(HDC PaintDC, PAINTSTRUCT _FAR & ps)
{
        //  Get window size
        RECT R;
        GetClientRect(HWindow, &R);

        //  Create memory bitmap and dc
        MemBmp = CreateCompatibleBitmap (PaintDC, R.right, R.bottom);
        MemDC = CreateCompatibleDC(PaintDC);
        SelectObject(MemDC, MemBmp);

        //  Draw on the memory dc
        Draw (MemDC);

        //  Blit to the screen
        BitBlt (PaintDC, 0, 0, R.right, R.bottom, MemDC, 0, 0, SRCCOPY);

        //  Clean up
        SelectObject(MemDC, MemBmp);
        DeleteDC(MemDC);
        DeleteObject (MemBmp);

Quote
}