TRFile

Fuente: 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

DATATypeDescription
hDCNumericFile handle for the output text file
aRowsArrayArray of character strings, one per row of the current page
cDocumentCharacterDocument name
nHeightNumericPage height in character rows
nWidthNumericPage width in character columns
lPrintLogicalEnable output (default .T.)

Methods

MethodDescription
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

Ver También