共用方式為


AdjustObjectSize Event

Occurs just before ReportListener begins rendering layout elements of type Shape or Picture.

PROCEDURE Object.AdjustObjectSize
LPARAMETERS nFRXRecno, oObjProperties

Parameters

Visual FoxPro passes the AdjustObjectSize event parameters in the following order:

  • nFRXRecno
    Integer data type, specifying the record number in the report or label definition file (frx or lbx) describing the layout element being rendered.
  • oObjProperties
    An object of Empty class, with members providing values relevant to adjusting the size of a Shape or Picture.

    oObjProperties member Type Usage

    reload

    Logical, defaults to .F.

    Flag to alert the ReportListener if you make changes.

    Set this value to True (.T.) to notify the ReportListener of changes to height or width.

    height

    Integer, valid values from 0 to 64000

    Height of layout element, in 960ths of an inch.

    If you change this value and set reload to .T., the ReportListener renders with the revised value.

    width

    Integer, valid values from 0 to 64000

    Width of layout element, in 960ths of an inch.

    If you change this value and set reload to .T., the ReportListener renders with the revised value.

    top,left

    Integer, readonly

    Coordinates of top- and left-most point of the Shape or Picture element. Provides information about the position of the layout element on the output page, for reference in calculations.

    reattempt

    Logical, readonly

    Indicates whether this element has been pushed to a second page because it did not fit on the previous page.

    maxheightavailable

    Integer, readonly

    Indicates the available room on this page for this element, allowing for the height of subsequent bands (such as the page footer) for which space must be reserved.

    Note

    Microsoft reserves the right to invoke AdjustObjectSize for additional report and label layout elements, as needed, and to add to the oObjProperties members appropriately for these additional layout element types. You can use nFRXRecno to test for layout element type, as shown in the sample code in Render Method.

Remarks

Applies To: ReportListener Object.

VisualFoxPro invokes AdjustObjectSize once for each layout element of type Shape or Picture, unless it finds no code in the derived ReportListener class at run time. It also does not call AdjustObjectSize if the element is in a band not marked Stretchable (fixed band height). For more information, see Report Band Properties Dialog Box.

Tip

To enhance performance, Visual FoxPro does not call either AdjustObjectSize or EvaluateContents if it determines that there is no code in the ReportListener for the event. If you usually include placeholder code or generalized code in every event, consider omitting such code for these two events, especially if the class level is abstract (never directly instantiated). Only include code at the class levels that actually use this functionality. The performance cost for AdjustObjectSize increases by approximately the same amount for each Shape or Picture element in a report; the performance cost for EvaluateContents varies. For more information, see EvaluateContents Event.

This feature is primarily for the use of ReportListeners interpreting certain Shapes as placeholders for custom objects, which they draw in the space reserved for the Shape in the layout.

AdjustObjectSize is not supported for Shapes or Pictures that stretch between any header and footer pair of bands, and does not support changes to shape curvature.

Although the oObjProperties parameter has several members, the only value that will affect the ReportListener’s rendering behavior is a change to oObjProperties.height. Change to oObjProperties.height is respected only if the new height is greater than the original height. This change will cause a change to the element’s height as rendered by the ReportListener and also cause other floating layout elements to be pushed down, and the band to stretch to accommodate the new height.

Because it is not supported for Shapes or Pictures that span bands, you cannot adjust the height of a Shape to continue through multiple pages. If the element does not fit on the page after the ReportListener has changed its height, the entire element will be pushed down to the next page. In some cases, because not all bands can span pages, this determination may result in the entire band being pushed to the next page. Refer to Report Bands for more information on which bands can span pages.

Use the oObjProperties.maxheightavailable member to determine the maximum size you can give the Shape or Picture without its being pushed entirely to the next page.

When you set a higher value than oObjProperties.maxheightavailable for oObjProperties.height and set oObjProperties.reload to True (.T.), the ReportListener's Render event is not called for this element on the current page. Instead, AdjustObjectPage is called again for the same element on the next page.

On the next page, oObjProperties.height is set back to its original value, oObjProperties.reattempt is set to True (.T.), and oObjProperties.maxheightavailable has a new value, based on the new value of oObjProperties.top on this page. At this point, you can re-evaluate the height you want for the element on the new page.

Warning

If you have set a height value too large for any page, the element will not display. No immediate error occurs, but continued assignments of such a value will cause the element to be re-pushed to subsequent pages repeatedly. Use oObjProperties.reattempt to avoid trying to reload the same value repeatedly, after your initial attempt.

Changes to the oObjProperties.width value do not affect the ReportListener’s base rendering behavior; however, they will be passed to your derived class for use in Render if oObjProperties.reload is True (.T.).

Both oObjProperties.height and oObjProperties.width have a valid range of 0 to 64000. If either value is set out of range, it snaps to 0 or 64000 and no error occurs.

oObjProperties.top and oObjProperties.left are read-only. They are passed for your derived class' reference, since there is no other way for the ReportListener to determine where in the page layout this instance of the element will be rendered.

Example

This example adjusts the height of a layout element in a report to display a differently-sized image for each record in a table. The filename for the image is stored in one column of the table and the desired image height (in inches) is stored in a second column of the table. The images referenced in each record may be a different height, and some records have no image file included. In the report layout, the image element is set to be only a few pixels high, an expression representing the table column holding the image filename is associated with this layout element. Elements in the same band below this region are set to float and stretch.

In the BeforeReport code, the ReportListener determines which record in the FRX layout definition describes the image, and saves this information for later use. When the AdjustObjectSize event occurs, the ReportListener checks its nFRXRecno argument to see if FRX element being evaluated matches its stored record number for the image element. If it does, the ReportListener adjusts the height of the image element to match whatever image is associated with this record.

Tip

Notice that the AdjustObjectSize code multiples the height value stored in the table by 960. The table stores its measurements in inches, and the ReportListener's rendering code handles measurements in 960 dots per inch (DPI).

DEFINE CLASS rl AS ReportListener
   FrxPic = 0
    
  PROCEDURE BeforeReport()
     SET DATASESSION TO (THIS.FRXDataSession)
     SELECT FRX
     LOCATE FOR ObjType = 17 && image
     IF EOF()
        THIS.FrxPic = 0
     ELSE
        THIS.FrxPic = RECNO()
     ENDIF
   ENDPROC

   PROCEDURE AdjustObjectSize(nFrxRecno,oProps)
       IF nFrxRecno = THIS.FrxPic 
          SET DATASESSION TO (THIS.CurrentDataSession)
          IF (NOT EMPTY(MyTable.picFile))
             * express in DPI units:
             oProps.Height = MyTable.picInches * 960
             oProps.Reload = .T.
          ENDIF
       ENDIF
   ENDPROC
   
ENDDEFINE

See Also

Tasks

How to: Add Shapes to Reports
How to: Add Pictures to Reports
How to: Set Stretching Report Controls

Reference

ReportListener Object
Round Rectangle Dialog Box
Rectangle/Line Dialog Box

Other Resources

Events (Visual FoxPro)
Language Reference (Visual FoxPro)