Home Devices
New Blog Posts: Merging Reports - Part 1 and Part 2

Print Cancel button does nothing

edited November 2002 in Devices
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;

Comments

  • edited November 2002
    Hi Larry,

    once the print job is sended, the application no more has control over it - that's Windows!

    regards,
    Chris Ueberall;
  • edited November 2002
    That may be true, but I put a Break point at "if lPrintDialog.ModalResult
    <> mrCancel then"
    and it is never tested! (see code below). That is before Windows takes
    over.
    Thanks


  • edited November 2002
    Hi Larry,

    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;
  • edited November 2002
    Check for multiple versions of the same dcu. If Delphi can find an older
    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

  • edited November 2002
    Thanks guys,
    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


This discussion has been closed.