(Updated: 2004.03.20 07:03:48 PM)
| |
At runtime, makes an FRX from the .Captions and .
Control Source props in a grid.
And then uses it to print the current data in the grid.
Search your VFP directry for the
Rpt Engin and Styles.frx
Here is the code in my grid.MkFrx method.
Create Cursor foo (dFid d, cFid1 c(10), cFid3 c(10) )
Insert into foo ( cFid1, dFid, cFid3 ) values ("A", Date(), "B" )
oGrid = CreateObject("iGrid")
oGrid.MkFrx
Return
Define Class iGrid as Grid
Procedure MkFrx
* make an frx
Set Path to d:\vfe\ilibs\reports\; D:\vfe\wizards\FRXWIZ\
Set Procedure to irptengin.prg, rptengin.prg, ivfeengin.prg, ifrxutils.PRG, wzengine.prg
#INCLUDE "d:\vfe\ilibs\vfp\RptEngin.H"
Local ;
lnSelect, ;
lnRecNo, ;
lcFrx, ;
loRepEngine, ;
lcStyleFile, ;
lnI, ;
loColumn, ;
lnWidth, ;
lnTotalWidth, ;
lcCaption
lnSelect = Select()
lnRecNo = RecNo()
lcFrx = Sys(2023)+"\TempGrid.frx"
loRepEngine = CreateObject( "iReportEngine", "", Set("Procedure") )
With loRepEngine
lnFields = this.ColumnCount
Dimension .aWizFList[lnFields,4]
Dimension .aWizFields[lnFields,1]
Dimension .aWizLabels[lnFields,1]
lnTotalWidth = 0
For lnI = 1 To lnFields
loColumn = this.Columns( lnI )
loHeader = loColumn.objects(1)
lcCaption = Trim( loHeader.Caption )
lcField = loColumn.ControlSource
lnWidth = Max( loColumn.width/7, Len(lcCaption) )
lnTotalWidth = lnTotalWidth + lnWidth
.aWizFList[lnI,1] = lcField
.aWizFList[lnI,2] = VarType( lcField )
.aWizFList[lnI,3] = lnWidth
.aWizFList[lnI,4] = 2
.aWizFields[lnI,1]= lcField
.aWizLabels[lnI,1]= lcCaption
Endfor
.nLayout = 1
lcStyleFile = "d:\vfe\ilibs\reports\Styles\StyleGrid1H.frx"
If lnTotalWidth < 50
.lLandscape = .f.
Else
.lLandscape = .t.
EndIf
Modify Report (lcStyleFile)
.cStyleFile = lcStyleFile
.cOutFile = lcFrx
.lUseTherm = .f.
.Process()
.Destroy()
Endwith
Report form (lcFrx) preview
* Report form (lcFrx) to printer
Select (lnSelect)
If lnRecNo<=Reccount()
Goto lnRecNo
EndIf
Return lcFrx
EndProc
EndDefine
Contribtors
Carl Karsten