title: How to create an intermediate canvas in delphi?
body: <p>I have an application where I need to print a graphic to a temporary TCanvas. My problem is that I can't refresh this canvas once I've drawn on it. Here's what I do:</p>
  
  <pre><code>var
    BitMap : TBitmap;
    WindowHandle : HWND;
    ScreenDC,bufferDC : HDC;
   bufferBitmap : HBitmap;
    tempcanvas : TCanvas;
  begin
    windowhandle := 0;
    tempcanvas := TCanvas.Create;
    screenDC := GetwindowDC(WindowHandle);
    BufferDC := CreateCOmpatibleDC(ScreenDC);
    TempCanvas.Handle := BufferDC;
    BufferBitmap := CreateCompatibleBitmap(ScreenDC, GetDeviceCaps(ScreenDC, HORZRES),
                                    GetDeviceCaps(ScreenDC,VERTRES));
    SelectObject(BufferDC,BufferBitmap);
    TempCanvas.Handle := getDeviceContext(windowHandle);
  (...)
  </code></pre>
  
  <p>The Canvas does not get refreshed when I move out of scope and then return with a new procedure call. Is there a clever way to do this with the globals I'm currently using, or do I need to use local variables, and if so, how to do that?</p>