TRFile
Fonte: source/classes/rfile.prg
Standalone class
TRFile is a text-file report output device that implements the same interface as TPrinter,
allowing reports to be written to a plain text file instead of a printer. It substitutes as
a device driver for TReport, providing Say(), StartPage(), EndPage(), and measurement
methods that operate on character cells rather than pixels.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
hDC | Numeric | File handle for the output text file |
aRows | Array | Array of character strings, one per row of the current page |
cDocument | Character | Document name |
nHeight | Numeric | Page height in character rows |
nWidth | Numeric | Page width in character columns |
lPrint | Logical | Enable output (default .T.) |
Methods
| Method | Description |
|---|---|
New( cFile ) | Open cFile for writing and create a TRFile device |
Say( nRow, nCol, cText, oFont, nMaxSize, u6, u7, nPad ) | Write text to the specified row and column in the character buffer |
StartPage() | Begin a new page; clears the row buffer |
EndPage() | Flush the current page buffer to the file |
End() | Close the output file |
SetHeight( nHeight ) | Set page height in character rows and reinitialize buffer |
SetSize( nWidth, nHeight ) | Set page dimensions in character cells |
GetTextWidth( cText ) | Returns Len( cText ) (character-based width) |
GetTextHeight() | Always returns 1 (single character row height) |
Example: Write Text Report to File
#include "FiveWin.ch"
function WriteTextReport()
local oFile := TRFile():New( "report.txt" )
oFile:SetSize( 80, 66 )
oFile:StartPage()
oFile:Say( 1, 30, "Monthly Report" )
oFile:Say( 3, 1, Replicate( "-", 80 ) )
oFile:Say( 5, 1, "Item" )
oFile:Say( 5, 40, "Amount" )
oFile:Say( 6, 1, Replicate( "-", 80 ) )
oFile:Say( 8, 1, "Widget A" )
oFile:Say( 8, 40, " 150.00" )
oFile:Say( 9, 1, "Widget B" )
oFile:Say( 9, 40, " 275.00" )
oFile:EndPage()
oFile:End()
return nil
Notes
- TRFile can be used as a drop-in replacement for TPrinter in TReport by setting
oReport:oDevice := TRFile():New( "out.txt" ). - Text positioning is character-based: row 1, column 1 is the top-left corner.
- Fonts, bitmaps, lines, and boxes are not supported (methods are VIRTUAL).
- Each page is buffered in
aRowsand flushed to disk onEndPage().