TRGroup
Fuente: source/classes/rgroup.prg
Standalone class
TRGroup defines a group break within a TReport. Groups enable hierarchical reports with group headers, footers, and automatic subtotals. When a group break occurs (detected by a change in the group expression value), the group footer is printed, totals are reset, and the group header for the new group is printed on the next page or following line.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
oReport | Object | Parent TReport object |
aTotal | Array | Array of accumulated subtotal values per column |
bGroup | Codeblock | Group expression; evaluated each row to detect breaks |
bHeader | Codeblock | Header text codeblock, printed when a new group starts |
bFooter | Codeblock | Footer text codeblock, printed when a group ends |
cValue | Character | Current group value |
cOldValue | Character | Previous group value, used for break detection |
nCounter | Numeric | Row count within the current group |
lEject | Logical | Eject page when group breaks |
lHeader | Logical | Has a header to print |
lFooter | Logical | Has a footer to print |
Methods
| Method | Description |
|---|---|
New( bGroup, bHeader, bFooter, bFont, lEject, oReport ) | Create a new TRGroup definition |
Header( nRow ) | Render the group header at the specified row |
Footer( nRow ) | Render the group footer at the specified row |
Total( nRow ) | Render column subtotals at the specified row |
Check() | Returns .T. if the group value has changed (break occurred) |
Evaluate() | Increment the group row counter |
Reset() | Reset totals, counter, and current/old values |
Stabilize( nOrder ) | Calculate header/footer dimensions |
Example: Group by State with Subtotals
#include "FiveWin.ch"
#include "report.ch"
function GroupedReport()
local oReport
REPORT oReport TITLE "Sales by State" PREVIEW
GROUPS oReport
GROUP ON { || oSale:State } ;
HEADER { || "State: " + oSale:State } ;
FOOTER { || "Subtotal for " + oSale:State }
COLUMN TITLE "Customer" DATA { || oSale:Customer }
COLUMN TITLE "Amount" DATA { || oSale:Amount } ;
PICTURE "9,999.99" TOTAL
END REPORT
ACTIVATE REPORT oReport
return nil
Notes
- Use the
GROUP ONcommand inside aREPORTblock to define group breaks declaratively. - Group breaks are detected automatically by comparing the current
bGroupevaluation against the previous value. - Set
lEject := .T.to force a page break each time the group value changes. - The
aTotalarray accumulates subtotals for columns that havelTotal := .T.. - Multiple group levels can be nested by defining multiple TRGroup objects in sequence.