Page 1 of 1

CANCELENABLE in DCPRINT

Posted: Tue Mar 16, 2010 11:33 am
by GeneB
When preparing a long report for preview or print, what is the way to enable an exit button?

The documentation says that CANCELENABLE adds a dialog window during printing with a Cancel button. I don't get a dialog window other than the one from BusyMessage. Can CancelEnable and BusyMessage be used together?
The "x" in the upper right corner of the "BusyMessage" does not cancel the preparation of the report. The stripped down code is below.
Can someone please show me what I'm doing wrong? Is there a method of doing this
similar to DC_Working? Thanks in advance.

DCPRINT ON ;
PREVIEW ;
BUSYMESSAGE "Preparing Report" ;
CANCELENABLE

lOkToPrint := .T.

FOR i:=1 TO LEN(aLines)

lOkToPrint := DC_PRINTEROK()

IF !lOkToPrint
EXIT
ENDIF

@ nRow,nCol DCPRINT SAY aLines
nRow++
NEXT

DCPRINT OFF

Re: CANCELENABLE in DCPRINT

Posted: Tue Mar 16, 2010 12:44 pm
by rdonnay
Here's how to do this using your own dialog.
This way you can have it display anything you want, even a progress bar.

Code: Select all

#include "dcprint.ch"
#include "dcdialog.ch"

FUNCTION Main()

LOCAL GetList[0], lOkToPrint, aLines[50],  i, oDlg, oProgress

DCPRINT ON ;
PREVIEW

@ 0,0 DCSAY 'Preparing report...' SAYSIZE 0
@ 2,0 DCPROGRESS oProgress SIZE 50,1 PERCENT
@ 4,0 DCPUSHBUTTON CAPTION 'Cancel' SIZE 10,1.2 ACTION {||lOkToPrint := .f.}
DCREAD GUI FIT MODAL TITLE 'My report' EXIT PARENT @oDlg

lOkToPrint := .T.

AFill(aLines,'Some text')

FOR i := 1 TO LEN(aLines)

  DC_GetProgress( oProgress, i, Len(aLines))

  DC_CompleteEvents()
 
  IF !lOkToPrint
    EXIT
  ENDIF

  @ nRow,nCol DCPRINT SAY aLines[i]
  nRow++

NEXT

oDlg:destroy()

IF lOkToPrint

  DCPRINT OFF

ELSE

  DCPRINT ABORT

ENDIF

Return nil