Print Cancel button does nothing
Below is the code I am using. It works fine but when the User attempts to
cancel a Print job (before starting) by Completing the Cancel button, it
still prints. Any suggestions?
Larry Killen
RBPro 5.56
D-5 Ent
I have walked the code but when Cancel is selected,
function TfrmRepQuote.SetupReport (DevType:String):Boolean;
var
lPrintDialog:TppPrintDialog;
pResult: boolean;
begin
pResult := true;
try
lPrintDialog:=nil;
if DevType = 'Printer' then
begin
try
rbOrder.DeviceType := dtPrinter;
rbOrder.SavePrinterSetup:= True;
lPrintDialog := TppPrintDialog.Create(self);
lPrintDialog.Printer := rbOrder.Printer;
lPrintDialog.ShowModal;
DialogToReport(lPrintDialog, rbOrder);
finally
if lPrintDialog.ModalResult <> mrCancel then //never called
pResult := true
else
pResult := false;
lPrintDialog.Free;
end;
end;
if DevType = 'Screen' then rbOrder.DeviceType := dtScreen;
except
on E: Exception do if MessageDlg('An error has occurred that will prevent
the previewing/printing '
+#13+#10+'of this report. Please contact
your Production '
+#13+#10+'Software Specialist for
assistance.',
mtWarning, [mbAbort], 0) = mrAbort then
pResult := false else pResult := true;
end;
result := pResult;
end;
procedure TfrmRepQuote.DialogToReport(aDialog: TppPrintDialog;
aReport: TppReport);
begin
aReport.PrinterSetup.Assign(TppPrinter(aDialog.Printer).PrinterSetup);
end;
cancel a Print job (before starting) by Completing the Cancel button, it
still prints. Any suggestions?
Larry Killen
RBPro 5.56
D-5 Ent
I have walked the code but when Cancel is selected,
function TfrmRepQuote.SetupReport (DevType:String):Boolean;
var
lPrintDialog:TppPrintDialog;
pResult: boolean;
begin
pResult := true;
try
lPrintDialog:=nil;
if DevType = 'Printer' then
begin
try
rbOrder.DeviceType := dtPrinter;
rbOrder.SavePrinterSetup:= True;
lPrintDialog := TppPrintDialog.Create(self);
lPrintDialog.Printer := rbOrder.Printer;
lPrintDialog.ShowModal;
DialogToReport(lPrintDialog, rbOrder);
finally
if lPrintDialog.ModalResult <> mrCancel then //never called
pResult := true
else
pResult := false;
lPrintDialog.Free;
end;
end;
if DevType = 'Screen' then rbOrder.DeviceType := dtScreen;
except
on E: Exception do if MessageDlg('An error has occurred that will prevent
the previewing/printing '
+#13+#10+'of this report. Please contact
your Production '
+#13+#10+'Software Specialist for
assistance.',
mtWarning, [mbAbort], 0) = mrAbort then
pResult := false else pResult := true;
end;
result := pResult;
end;
procedure TfrmRepQuote.DialogToReport(aDialog: TppPrintDialog;
aReport: TppReport);
begin
aReport.PrinterSetup.Assign(TppPrinter(aDialog.Printer).PrinterSetup);
end;
This discussion has been closed.
Comments
once the print job is sended, the application no more has control over it - that's Windows!
regards,
Chris Ueberall;
<> mrCancel then"
and it is never tested! (see code below). That is before Windows takes
over.
Thanks
if you enter the try/finally section, the 'never called' line will be called. Place a 'ShowMessage' at the begining to verify it. Breakpoints are sometimes a bit puzzled in Delphi.
regards,
Chris Ueberall;
one with debug info, while debugging, it can throw the breakpoints out of
alignment on the pas file that you have open in Delphi.
I ran your code and the break points worked fine in RB 7 D6.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
Mistake is mine. I had inadvertantly dropped the return value from the
SetupReport function some time back and failed restored it.
Got it working.
Still got an issue on adding a field to a group. Please see other Help
request