Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Better way to do orphan/widow in a report
Message
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01158138
Message ID:
01159509
Views:
35
Hi Albert,

>To answer the first question: the goal is to make sure that there are always 2 detail lines on the last page - the other pages typically are filled with detail lines so it is mainly the last page that I have to deal with.

OK, then the code will have to be tweaked slightly. (see below)

>From the code below, what is oProp - is it an object of the report listener?

oProp my my shorter version of oObjectProperties. See the VFP9 help file's AdjustObjectSize Method entry for more details. This property is passed to the AdjustObjectSize event from the ReportListener.

>I also don't know how to "hook" the object into the report - did not see a spot under any of the properties of the report to specify a report listener object class - maybe it is somehow invoked off the command line for REPORT FORM...will go looking this morning.

It's as easy as specifying an OBJECT clause for the REPORT FORM command. There are other options also, but this is the easiest to try it out:

oMyRL = CREATEOBJECT("MyRL")
oMyRL.ListenerType = 1 && Preview
REPORT FORM MyReport OBJECT oMyRL

I tweaked the code (unfinished) to use a seperate table to track the 3rd from the bottom record. This should have even less impact on your existing code.
DEFINE CLASS MyRL AS ReportListener

nStretchRect = 0   && Recno of our stretchy rectangle
...

FUNCTION BeforeReport
  LOCAL lcGroupExpr

  ** Find the stretchy rectangle
  SET DATASESSION TO (This.FRXDataSession)
  SELECT frx
  
  ** Find the Group expression
  lcGroupExpr = ""
  LOCATE FOR objtype=9 and objcode=4
  IF FOUND()
    SKIP -1
    IF objcode = 3
      lcGroupExpr = expr
    ENDIF
  ENDIF

  ** Find the dummy rectangle
  LOCATE FOR "*:stretchy" $ comment
  IF FOUND()
    This.nStretchRect = RECNO()
  ENDIF
  SET DATASESSION TO (This.CurrentDataSession)

  ** Create a temp table to track our 3rd from the bottom
  ** record for each group
  lnSelect = SELECT()
  CREATE CURSOR curDetailBreak (recno i)
  INDEX ON recno TAG recno
  SELECT (lnSelect)

  *! ToDo: FInish this code
  ** Scan through the cursor looking for group
  ** changes and insert the 3rd from the bottom RECNO()
  ** of each group into curDetailBreak
  leLastGroupValue = EVALUATE(lcGroupExpr)
  lnRecno = RECNO()
  SCAN
    leThisGroupValue = EVALUATE(lcGroupExpr)
    IF leLastGroupValue != leThisGroupValue
      ** Save the current record position
      lnLastRecNo = RECNO()
      ** go back 2 records
      SKIP -1
      SKIP -1
      ** store the recno in the temp cursor
      INSERT INTO curDetailBreak (recno) VALUES (RECNO())
      LOCATE RECORD (lnLastRecNo)
    ENDIF
    leLastGroupValue = EVALUATE(lcGroupExpr)
  ENDSCAN
  SKIP -1
  SKIP -1
  INSERT INTO curDetailBreak (recno) VALUES (RECNO())
  LOCATE RECORD (lnRecNo)
ENDFUNC


FUNCTION AfterReport
  ** Close the temp table
  USE IN SELECT("curDetailBreak")
ENDFUNC


FUNCTION AdjustObjectSize(nFRXRecNo, oProp)
  IF nFRXRecNo = This.nStretchRect AND SEEK(RECNO(),"curDetailBreak")
    ** We are on the stretch rectangle and the 3rd from
    ** the bottom record...
    ** Force a new page by making the rectangle equal to 
    ** the max size
    oProp.Height = oProp.MaxHeightAvailable
    oProp.Reload = .T.
  ENDIF
ENDFUNC

ENDDEFINE
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform