使用TPrinter类的BeginDoc方法提示"Printer currently is not Printing",怎么解决。源码如下:const
DRV_NAME_BAT500_FULLCUT: String = 'EPSON BA-T500 Full cut';function TPrinterComm.Print: Integer;
var
i: Integer;
printerName: String;
begin
Result := 0; for i := 0 to FPrinter.Printers.Count - 1 do // Iterate
begin
printerName := FPrinter.Printers.Strings[i];
if printerName = DRV_NAME_BAT500_FULLCUT then begin
FPrinter.PrinterIndex := i;
Break;
end;
end; // for with FPrinter do
begin
if Printing then begin
Abort;
Result := -1;
Exit;
end; try
BeginDoc;//出错
Canvas.TextRect(Rect(200,200,PageWidth-200,PageHeight-200),
200, 200, '食堂餐券' + #13 + #13 + '8元');
Except
Abort;
Result := -2;
end; EndDoc;
end; // with
end;
请高手指点。
DRV_NAME_BAT500_FULLCUT: String = 'EPSON BA-T500 Full cut';function TPrinterComm.Print: Integer;
var
i: Integer;
printerName: String;
begin
Result := 0; for i := 0 to FPrinter.Printers.Count - 1 do // Iterate
begin
printerName := FPrinter.Printers.Strings[i];
if printerName = DRV_NAME_BAT500_FULLCUT then begin
FPrinter.PrinterIndex := i;
Break;
end;
end; // for with FPrinter do
begin
if Printing then begin
Abort;
Result := -1;
Exit;
end; try
BeginDoc;//出错
Canvas.TextRect(Rect(200,200,PageWidth-200,PageHeight-200),
200, 200, '食堂餐券' + #13 + #13 + '8元');
Except
Abort;
Result := -2;
end; EndDoc;
end; // with
end;
请高手指点。
var h,w:longint;
begin
Screen.Cursor := crHourGlass; { <-- nice detail }
try
Printer.BeginDoc; { <-- start printer job }
try
{ now print some text on printer.canvas }
With Printer.Canvas do
begin
Font.Name:='Arial';
Font.Size:=10; { <-- set the font size }
Font.Style:=[];
TextOut(0,0,Edit1.Text); { <-- print some text }
end; h:=Printer.PageHeight; { <-- get page height }
w:=Printer.PageWidth; { <-- get page width } { And now print the chart component... }
Chart1.PrintPartial( Rect( w div 10, { <-- left margin }
h div 3 , { <-- top margin }
w - (w div 10), { <-- right margin }
h - (h div 10) )); { <-- bottom margin }
{ print more text.... }
With Printer.Canvas do
begin
Font.Name:='Arial';
Font.Size:=12; { <-- set the font size }
Font.Style:=[fsItalic];
TextOut(0,60,Edit1.Text+' ...again'); { <-- print some text }
end; Printer.EndDoc; { <-- end job and print !! }
except
on Exception do { just in case an error happens... }
Begin
Printer.Abort;
Printer.EndDoc; {注意,异常的话也要EndDoc,你在BeginDoc的时候出错,会不会是因为前一次打印的时候出现异常,但是又没有EndDoc?}
Raise; { <-- raise up the exception !!! }
end;
end;
finally
Screen.Cursor:=crDefault; { <-- restore cursor }
end;
end;