Staz Software
HomeFutureBasicSharewareOrderContact

Tech Notes

Printing Causes a Crash

When you use CLOSE LPRINT or CLEAR LPRINT, the grafport that was in use (the printer) is tossed away. If your code expects a valid grafport, it's in deep trouble. Consider this:

/* Bad example */

ROUTE _toPrinter
FOR x = 1 TO maxPages
 FN print1Page(x)
 LONG IF x = maxPages
  CLOSE LPRINT        ' May cause a crash
 XELSE
  CLEAR LPRINT        ' May cause a crash
 END IF
NEXT

ROUTE _toScreen

When the CLEAR or CLOSE LPRINT is encountered the drawing surface where we were scribbling goes away. Subsequent scribbles against that surface will fall through to some other indeterminate place. In System 9, you will almost certainly crash. If you don’t crash in System 8, you’ll at least get a headache. System 7 usually (but not always) survived.

The cure is a simple one. When you finish printing a page, route the output back to the screen before you eject it. The example below relocates the ROUTE commands and works in all versions of the system software.

/* Good example */

FOR x = 1 TO maxPages
 ROUTE _toPrinter       ' Turn printer on
 FN print1Page(x)
 ROUTE _toScreen        ' Turn printer off
 LONG IF x = maxPages
  CLOSE LPRINT
 XELSE
  CLEAR LPRINT
 END IF
NEXT

FutureBASIC

Demo

Order

Tour

Tech Notes

FAQ

Sample Code

Web Sites

Mailing List

System
Requirements

blank