Page 1 of 1

Printer class: selection errors

Posted: Mon Apr 02, 2018 7:44 pm
by TimStone
This is from a client ... and I need to trap it.

Using the tPrinter class for a report:
1). Using PRINT oPrn NAME "Workorder Printing" FROM USER // Send to user selected printer
2).The printer selection dialog pops up.
3) Instead of selecting a printer, the user clicks the Cancel button
4). The program gets a Windows error that the program has stopped working.

How can I trap and respond to this cancel button ?

Please ... don't ask me why he does this. That is beyond me since he has many other options in the process where he can cancel, but he does it here ...

Re: Printer class: selection errors

Posted: Mon Apr 02, 2018 8:25 pm
by Enrico Maria Giordano
The following sample doesn't error out here. Please change it to show the error.

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    @ 1, 1 BUTTON "Print";
           ACTION PRINT()

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


STATIC FUNCTION PRINT()

    LOCAL oPrn

    PRINT oPrn NAME "Test" FROM USER PREVIEW
        PAGE
            oPrn:Say( 0, 0, "Test" )
        ENDPAGE
    ENDPRINT

    RETURN NIL
EMG

Re: Printer class: selection errors

Posted: Mon Apr 02, 2018 8:59 pm
by TimStone
Enrico Maria Giordano wrote:The following sample doesn't error out here. Please change it to show the error.

EMG
Remove PREVIEW, then when the printer selection dialog appears, hit Cancel.

If Cancel is selected, then oPrn is not created ( I assume ), so it's possible other actions involving oPrn would then fail. How can I trap for that Cancel ?


Sent from my iPhone using Tapatalk

Re: Printer class: selection errors

Posted: Mon Apr 02, 2018 9:40 pm
by Enrico Maria Giordano
I removed PREVIEW clause: still no errors clicking Cancel button.

EMG

Re: Printer class: selection errors

Posted: Mon Apr 02, 2018 11:22 pm
by TimStone
OK ... It's just on one very complex invoice print routine.

I suppose it's time to go back and do a section by section "comment out" test to find where it creates the error ... and see if some of my code perhaps conflicts with the class.

Thanks for looking at that.

Of course I have no idea why the client is doing this ...

Tim

Re: Printer class: selection errors

Posted: Tue Apr 03, 2018 10:56 pm
by dtussman
I always use this and it works:

PRINT oprn name pname from user
IF EMPTY( oprn:hdc )
RETURN nil
ENDIF

Re: Printer class: selection errors

Posted: Tue Apr 03, 2018 11:08 pm
by TimStone
Thanks ... works perfectly in this case.