[Gambas-user] Report component - variable height items

Bruce bbruen at ...2308...
Fri Jan 10 04:07:47 CET 2014


> > Works like an old rag!
> Is it good or bad ?

Sorry! A bit of "Australian" crept in there. It means good.


Now, here is a couple of new problems (and hopefully an answer).


We have an audit requirement to create a "hard copy" of a thing when
its' data is first entered into the system. Since there will be
hundreds, if not thousands, of these things I have convinced the
auditors to let us create a read-only pdf file rather than chewing up so
much paper. Fine, so the requirement now becomes a technical
requirement: When a thing is first inserted into the database,
automatically print-to-file a gb.report of the data and set its' attribs
to -r--r--r--

The first and last bits are not a problem, it's that middle bit
"automatically print-to-file a gb.report of the data". Why it is a
problem is a bit hard to explain, but here goes.

We want no user interaction. So instead of showing the preview form, it
has just got to print. In fact we don't even want to see the printer
selection form (but I'll get to that later). Tracing through the call
stack, I get to CPrint.PrintReport:

7  Public Sub PrintReport(hReport As Report)
8
9    Dim hSizeParse As TSizeParse
10
11    $hPrint = hReport.Clone()
12    hPrinter.Paper = $hPrint.Paper
13    hPrinter.Orientation = $hPrint.Orientation
14    If $hPrint.Paper = Printer.Custom Then
15      hSizeParse = New TSizeParse($hPrint.Width)
16      hPrinter.PaperWidth = hSizeParse.ToCm() / 10
17      hSizeParse = New TSizeParse($hPrint.Height)
18      hPrinter.PaperHeight = hSizeParse.ToCm() / 10
19    Endif
20    If Not hPrinter.Configure() Then
21      hPrinter.Print
22    Endif
23
24  End

The first issue is at line 11, I can't understand why you create a clone
of the report object and it creates a problem as follows: Report.Clone
invokes the _new() method in the actual report class. However, our _new
method requires a parameter, the database record id for the "thing" we
want to print. So we get a "not enough parameters" error. (I tried
getting around this by using a "Run(id)" method, but of course this
never gets invoked in the cloned object and thus we get a blank report.)
I have changed line 11 to 

11    $hPrint = hReport   '.Clone()

locally and everything still works. But I am a bit scared that there is
something I don't know about that requires that cloning to occur. Is
there?

Now we get to line 20. This is a bit unconditional!  We need a way to
skip running the preview. Anyway, after a bit of mucking about I decided
that Report needed two new properties (DefaultPrinter and ShowPreview)
and CPrint needed some changes.  I have attached a gzip of these
classes.  See what you think about adding these changes to the base.
(Note: it does have that line 11 change.)

Basically, ShowPreview defaults to True and since DefaultPrinter will be
null, there should be no side effects on existing reports.  ShowPreview
is set to appear in the IDE Report designer, so it is a simple matter to
turn it off or on. DefaultPrinter doesn't appear in the IDE, it is a
"code-only" property.

What turned out to be "cool" is that just by creating a DefaultPrinter,
it automatically selects the users actual default printer (or the system
default if the user hasn't got one). So that makes it possible to bypass
the Printer.Configure() call and the report will go to the default
printer automagically. What I found to be even "cooler" is how to set it
to print-to-file. 

   Me.DefaultPrinter = New Printer
   With Me.DefaultPrinter
     .Name = ""
     .OutputFile = "~/print1.pdf"
   End With

in the myreport.class and bingo! i.e. just set the printer name to null
and the OutputFile property to wherever you want the report to go.
Setting the filename extension magically produces a pdf file, setting it
to anything else magically produces a postscript file.

regards
Bruce
-------------- next part --------------
A non-text attachment was scrubbed...
Name: changes.tar.gz
Type: application/x-compressed-tar
Size: 3864 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20140110/7c8a93bc/attachment.bin>


More information about the User mailing list