Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Nov 17, 2017 2:18 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: TurboReport DrawPage method added
PostPosted: Thu May 20, 2010 11:21 pm 
Offline

Joined: Tue Oct 06, 2009 2:38 am
Posts: 435
One limitation in TurboReport is that a single large Picture object is created from all the individual pages in the report when the finishReport method is called. This is not ideal from performance, memory-management, user-experience and developer-control viewpoints. We may also run into the internal limits of the Picture object, with unpredictable results.

The code for rendering the final picture was simply re-factored into a new method called drawPage that renders each page onto the screen as required. Now all we need to do is to add forward/back controls that will call drawPage to render the current page onto the Canvas.

sub drawPage( pageNumber As Integer, percent As Integer = 25 )
dim x1 as integer
dim y1 as integer

dim x2 as integer
dim y2 as integer


me.ReportPicture = NewPicture(me.PaperWidth+(mm2px(BACKGROUND_MARGIN_MM)*2), me.PaperHeight+mm2px(BACKGROUND_MARGIN_MM)+mm2px(BACKGROUND_MARGIN_MM), 32)

' fill image with background (background outsite the pages)
ReportPicture.Graphics.ForeColor = BACKGROUND_REPORT_COLOR
ReportPicture.Graphics.FillRect 0, 0, ReportPicture.Width, ReportPicture.Height

' draw shadow on picture
ReportPicture.Graphics.ForeColor = RGB(0, 0, 0)

x1 = mm2px(BACKGROUND_MARGIN_MM) + mm2px(0.5)
y1 = mm2px(BACKGROUND_MARGIN_MM)+ mm2px(0.5)

x2 = me.PaperWidth+2
y2 = me.PaperHeight+2

ReportPicture.Graphics.FillRect x1, y1, x2, y2

' draw picture on image
ReportPicture.Graphics.DrawPicture me.Pages(i), mm2px(BACKGROUND_MARGIN_MM), mm2px(BACKGROUND_MARGIN_MM)

' draw rectangle around the page
ReportPicture.Graphics.ForeColor = RGB(0, 0, 0)
ReportPicture.Graphics.PenHeight = 1
ReportPicture.Graphics.PenWidth = 1

x1 = mm2px(BACKGROUND_MARGIN_MM)-1
y1 = mm2px(BACKGROUND_MARGIN_MM)-1

x2 = me.PaperWidth+2
y2 = me.PaperHeight+2

ReportPicture.Graphics.DrawRect x1, y1, x2, y2

ReportPicture = me.internScaleImage(ReportPicture, ceil(ReportPicture.Height*percent/100), ceil(ReportPicture.Width*percent/100))

' set scrollbars
if me.ReportPicture.Height > MyCanvas.Height then
ScrollBarY.Maximum = me.ReportPicture.Height-MyCanvas.Height
else
ScrollbarY.Maximum = 0
end if

if me.ReportPicture.Width > MyCanvas.Width then
ScrollBarX.Maximum = me.ReportPicture.Width-MyCanvas.Width
else
ScrollbarX.Maximum = 0
end if
end sub
Now that we have more control over how each page is rendered, we also gain the benefit of being able to control how the header/footer on each page will look like.


Top
 Profile  
Reply with quote  
 Post subject: Re: TurboReport DrawPage method added
PostPosted: Thu Oct 07, 2010 6:44 pm 
Offline

Joined: Thu Oct 07, 2010 5:50 pm
Posts: 5
I just installed TurboReport on RBv3.2. I have a simple list report that pulls from a recordset with 3700 rows. The report stops at record no 1776 which looks like a page break on around page no 37. I thought it might be corrupted data so I ordered the rs by another field and got the same results. Then I thought it might be memory so I watched my memory while the program ran and had plenty. Is there some limit on the number of pages I can generate?

Thanks
Bill


Top
 Profile  
Reply with quote  
 Post subject: Re: TurboReport DrawPage method added
PostPosted: Thu Oct 07, 2010 8:41 pm 
Offline

Joined: Tue Oct 06, 2009 2:38 am
Posts: 435
Bill, I do not have any experience with such an old version of RS... how long does it take to generate the print preview? What is the memory usage when the report is generated? What OS?


Top
 Profile  
Reply with quote  
 Post subject: Re: TurboReport DrawPage method added
PostPosted: Thu Oct 07, 2010 11:14 pm 
Offline

Joined: Thu Oct 07, 2010 5:50 pm
Posts: 5
Oops, sorry I wasn't clear. I'm running RB 2010 release release 3.2. Brand new...


Top
 Profile  
Reply with quote  
 Post subject: Re: TurboReport DrawPage method added
PostPosted: Fri Oct 08, 2010 9:24 am 
Offline

Joined: Sat Mar 04, 2006 10:39 am
Posts: 660
Does TurboReport do subsummaries?

Thanks,

_________________
Michael

Real Studio Professional 2010 R5.1
Mac OS X 10.6.6
2.53 GHz Intel Core i5
with 4 GB of memory


Top
 Profile  
Reply with quote  
 Post subject: Re: TurboReport DrawPage method added
PostPosted: Fri Oct 08, 2010 10:52 pm 
Offline

Joined: Tue Oct 06, 2009 2:38 am
Posts: 435
@bcassels: if you didn't implement the drawPage method as posted, then it's likely you might've run into the internal size limits of the Graphics object. Because the Graphics width and height properties are Integer (32-bit), probably that's the limit. Perhaps an RS engineer can shed some light on this.

@mvreade: no it doesn't but there's nothing stopping you from implementing it yourself


Top
 Profile  
Reply with quote  
 Post subject: Re: TurboReport DrawPage method added
PostPosted: Fri Oct 08, 2010 11:12 pm 
Offline

Joined: Thu Oct 07, 2010 5:50 pm
Posts: 5
Does drawPage subsitute internUpdateReport() on MyCanvas.Paint ? If it does where does the variable PageNumber As Interger come from in the drawPage(PageNumber As Integer, percent As Integer = 25)

Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: TurboReport DrawPage method added
PostPosted: Mon Feb 27, 2012 7:50 pm 
Offline

Joined: Fri Jun 02, 2006 1:43 pm
Posts: 209
Location: Santa Ynez, CA
I am using TurboReport and get a warning whenever I analyze my project saying that Graphics is deprecated and to use Paint instead. As Graphics is a property and Paint is an event, I am hoping that someone can post an updated version of the DrawPage method that uses Paint instead of Graphics.


Top
 Profile  
Reply with quote  
 Post subject: Re: TurboReport DrawPage method added
PostPosted: Sun Mar 18, 2012 12:37 pm 
Offline

Joined: Fri Jun 02, 2006 1:43 pm
Posts: 209
Location: Santa Ynez, CA
Well, I finally sat down and figured out how to do this myself. To save others some time (and I hope, some confusion), here is what I came up with.

Regarding the deprecated graphics property, change the MyCanvas.Paint event to
Sub Paint(g As Graphics)
internUpdateReport(g)
End Sub
Change the internUpdateReport method to
Private Sub internUpdateReport(g As Graphics)
' show current report in the needed place

' fill background
g.ForeColor = BACKGROUND_REPORT_COLOR

g.FillRect 0, 0, MyCanvas.Width, MyCanvas.Height

' drawrect arround background
g.ForeColor = RGB(0, 0, 0)
g.PenHeight = 1
g.PenWidth = 1
g.DrawRect 0,0, me.Width, me.Height

' stop when report is not ready
if ReportPicture = nil then
return
end if

' get left margin for canvas (when canvas is bigger that page)
dim left_margin as integer = 0

if MyCanvas.Width > ReportPicture.Width then
left_margin = floor((MyCanvas.Width-ReportPicture.Width)/2)
end if

' draw report
g.DrawPicture me.ReportPicture, left_margin, 0, MyCanvas.width, MyCanvas.height, ScrollbarX.value, ScrollbarY.value, MyCanvas.width, MyCanvas.height
End Sub
In the showReportMM method, and anywhere else you call internUpdateReport, change that call to MyCanvas.Refresh so that the graphics object is passed to internUpdateReport.

Regarding the pageDraw subroutine detailed above by brisance, call it instead of showReportMM whenever you want to show just one page. I also changed the (i) to (pageNumber-1) in
ReportPicture.Graphics.DrawPicture me.Pages(i), mm2px(BACKGROUND_MARGIN_MM), mm2px(BACKGROUND_MARGIN_MM)
I had earlier gotten around the out of memory problem with the graphics object by stepping through a recordset creating a new report for each record. Some of my users print 500 or more invoices at a time and the possibility of an an out of memory exception exists if they may try to print several months worth at one time so I may keep that routine.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group