Faceți căutări pe acest blog

joi, 29 octombrie 2015

How to move an entire band to the next page, if contains an object that spans to the next page.

Report's details can have long descriptions.
If a detail's long description overflows the page, then I see its remainder in the following page.

To avoid that and to put all the item (with its whole description) in the following page, SET REPORTBEHAVIOR 90 must be used.

This post shows a solution without subclassing the reportlistener, but it's slow and not intuitive.
Basically, the report is executed more times. Each time one more record is moved to the next page.
Because moving a single record to the next page rearrange the remaining records, the procedure must be repeated, until no record has to be moved.
The RECNO() of the records that spans to the next page, are stored into a cursor named "tproblems" (you can use other name, but you must change that name in the report; see steps 3 and 4 from below)

A demo prg with the report is attached in this rar archive containing a smal prg and a report

Description
1) the piece of code to prepare and finally show the report
*************
* Begin code
*************
CREATE CURSOR tproblems (nRec I) && cursor that retains all the record that tried to span across the pages
PRIVATE llRetry,lnReccount,llOneMoreTime,llBreak && some variables used by the report
llRetry = .T.
lnReccount = 0
SET REPORTBEHAVIOR 90
DO WHILE llRetry && because each record moved to the next page rearrange the remaining records, the procedure must be repeated one by one
    llOneMoreTime = .F.
    llBreak = .F.
    REPORT FORM MyReport TO test.txt  && test.txt can be change with any other name
    llRetry = llOneMoreTime
    lnReccount = lnReccount + 1
ENDDO
llBreak = .F.
REPORT FORM MyReport PREVIEW && the final report

*************
* End code
*************

 2) Open the report and add a new group, by llBreak and set New Page


3) Double click the field that expands to the next page, choose Field properties, and go to the Other Tab.
Click Edit Settings from the Run-time extensions.
Type llRetry in Execute When, and in the edit box above it :

*********
* Begin
*********
 if tP6 = 1 AND RECCOUNT('tproblems') = lnReccount
  insert into tproblems values (recno(ALIAS()))
  llOneMoreTime = .T.
endif

*********
* End
*********





4) Double click the Details band, choose Detail Band properties, and go to the Other Tab.
Click Edit Settings from the Run-time extensions.
Type AfterBand in Execute When, and in the edit box above it :

*********
* Begin
*********
lcAlias = ALIAS()
SELECT tproblems
LOCATE FOR nRec = RECNO(lcAlias) + 1
IF FOUND()
  llBreak = !llBreak
ENDIF
SELECT (lcAlias)


*********
* End
*********



Foxite link

Niciun comentariu:

Trimiteți un comentariu