Io ho replicato il codice di stampa definito nella classe TForm all'interno di una classe derivata da TFrame; questo è il codice:
codice:
procedure TMyFrame.Print;
var
  PageImage: TBitmap;
  Bits: HBITMAP;
  InfoSize, ImageSize: DWORD;
  Info: PBitmapInfo;
  Image: Pointer;
  dw, dh, pw, ph: Longint;
begin
  Printer.BeginDoc;
  try
    PageImage := GetPageImage;
    try
      Bits := PageImage.Handle;
      GetDIBSizes(Bits, InfoSize, ImageSize);
      Info := AllocMem(InfoSize);
      try
        Image := AllocMem(ImageSize);
        try
          GetDIB(Bits, 0, Info^, Image^);
          with Info^.bmiHeader do
          begin
            dw := biWidth;
            dh := biHeight;
          end;
          case FPrintScale of
            poProportional:
            begin
              pw := MulDiv(dw, GetDeviceCaps(Printer.Handle, LOGPIXELSX), 96);
              ph := MulDiv(dh, GetDeviceCaps(Printer.Handle, LOGPIXELSY), 96);
            end;
            poPrintToFit:
            begin
              pw := MulDiv(dw, Printer.PageHeight, dh);
              if pw < Printer.PageWidth then
                ph := Printer.PageHeight
              else begin
                pw := Printer.PageWidth;
                ph := MulDiv(dh, Printer.PageWidth, dw);
              end;
            end;
          else
            pw := dw;
            ph := dh;
          end;
          StretchDIBits(Printer.Canvas.Handle, 0, 0, pw, ph, 0, 0, dw, dh,
            Image, Info^, DIB_RGB_COLORS, SRCCOPY);
        finally
          FreeMem(Image, ImageSize);
        end;
      finally
        FreeMem(Info, InfoSize);
      end;
    finally
      PageImage.Free;
    end;
  finally
    Printer.EndDoc;
  end;
end;