> After another good bit of testing, I have a proposed explanation of the
> printing crashing, a new revelation, and a question or two:
> 
> 1. Populating a printersetup using ps.setupstring = SetupString randomly fails
> silently (and fails much more often on HP and network printers)

I've just stumbled on what think is a simple, 100% reliable workaround.
Here's the rule:

ps.setupstring = anything is evil. Don't EVER use this assignment!!
(at least until REAL fixes it).

Here's some code that demonstrates how I can now reliably print in Windows:
 
  // This always returns a valid ps for your default printer
  dim ps as  new PrinterSetup
  
  // Optional: If you need to access page setup,
  // this always returns a valid printersetup object
  Call ps.PageSetupDialog

  dim g as Graphics = OpenPrinterDialog(ps)
   // I had never realized ps is modified by OpenPrinterDialog(ps)
  //  ps now is populated reliably for the printer selected in your
  //  printer dialog -- even if you select a non-default printer.

  g.drawstring "Hello World", 100,100
  g = nil
    
  While NOT UserCancelled
    x = x + 1
    
    g = OpenPrinter(ps)
    g.drawstring "Hello World", 100,100
    g = nil
    
    EditField1.text = str(x)
    EditField1.Refresh
   
    // In a fascinating twist, getting the setupstring never crashes
    EditField2.text = str(ps.setupstring)
    EditField2.Refresh
   
  Wend
  
I just ran this for over 100,000 print jobs on my most troublesome HP 1320
printer driver with zero crashes.

If you have multiple reports requiring differing formats, use ps() as
printersetup as an array, creating a new setup for each type of report
printed. 

I think the minor inconvenience of confirming the printer, orientation and
margins -- if needed -- once per program run is more than an acceptable
workaround until REAL can fix assigning to .setupstring.

Does anyone see a problem or fatal flaw with this workaround in their apps?

Keith DeLong


 



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to