邪门了,在 QuickRep 预览时保存为 .QRP 文件再调用后,打印就行了。但不能打印
指定页数。是何原因?
如果能调用,说明你的代码正常,很可能是 QuickRep 的事情。
跟踪源码试一试。可以从Qrprev.pas入手。
这段代码是打印之类的很好的示例:
Qrprntr.pas
////////////
procedure TQRPrinter.Print;
type
TSmallPoint = record
X,
Y : integer;
end;
var
I : integer;
aPoint : TSmallPoint;
ASize : TPoint;
APage : TMetafile;
FromPage, ToPage: integer;
begin
{$ifdef EVAL}
if not DelphiRunning then
MessageDlg('Unregistered evaluation copy - Printing is only allowed while Delphi is running',mtWarning,[mbOK],0) //do
not locallize
else
{$endif}
{$ifdef VER36PRO}
if assigned(FMaster) and not ReportLoaded and ( not PrintMetafile and (Status = mpFinished)) then
{$else
}
if assigned(FMaster) and not ReportLoaded then
{$endif}
PostMessage(Master.Handle, CM_QRPRINT, 0, 0) //发消息。
else
// print metafile
if (Status = mpFinished) and PrinterOK then
//////请仔细体会如下代码。
try
APrinter.Title := Title;
if APrinter.Printing then
APrinter.Abort;
{$ifdef VER36PRO}
self.aPrinterSettings.ApplySettings;
{$endif}
APrinter.begin
Doc;
FromPage := 1;
//其始页
ToPage := PageCount;
//终止页
if FirstPage <> 0 then
FromPage := FirstPage;
if LastPage <> 0 then
ToPage := LastPage;
for I := FromPage to ToPagedo
begin
Application.ProcessMessages;
PageNumber := I;
aPoint.X := GetDeviceCaps(APrinter.Handle, PHYSICALOFFSETX);
aPoint.Y := GetDeviceCaps(APrinter.Handle, PHYSICALOFFSETY);
aSize.X := GetDeviceCaps(APrinter.Handle, PHYSICALWIDTH);
aSize.Y := GetDeviceCaps(APrinter.Handle, PHYSICALHEIGHT);
APage := GetPage(I);
try ///使用了Canvas
APrinter.Canvas.StretchDraw(Rect(0, 0, APrinter.PageWidth, APrinter.PageHeight), APage);
finally
APage.Free;
end;
// if I < PageCount then
APrinter.NewPage;
if I < ToPage then
APrinter.NewPage;
if Cancelled then
APrinter.Abort;
end
finally
if APrinter.Printing then
APrinter.EndDoc;
end;
end;