Quick Start to Running Visual FoxPro
Reports using the Mind's Eye Report Engine
All of the code on this page can be used in
Visual FoxPro version 6.0 and above. To test the code with the Mind's Eye Report
Engine simply highlight the code here on the web page and then cut and paste the
code into the VFP Command Window. Then highlight all of the code and hit the
Enter Key to execute the code in the VFP Command Window. You can also cut and
paste the code into a PRG file and run the PRG file as well. Make sure that you
use the SET PATH TO command to make sure that the MindsEyeReportEngine Class
Library can be found. Otherwise, you must place the path into the SET CLASSLIB
TO line of code for all of the examples.
Previewing a VFP FRX Report
It is very easy to run a
Visual FoxPro FRX Report with the included Visual Class Library. The only code
SET
CLASSLIB TO MindsEyeReportEngine
PUBLIC oRPT
oReportEngine = CREATEOBJECT('MindsEyeReportEngine')
*
The following line of code runs the VFP Report and returns an
* Object Reference to
a VFP Form hosting the Report Engine ActiveX Control
oRPT =
oReportEngine.ReportFormObject('SomeReport.FRX')
oRPT.Show()
After running the code
above, the report will be displayed inside the ActiveX control which is hosted
by a Visual FoxPro Form.
Running VFP FRX Reports without a User Interface
If for example, you wish to
generate PDF documents from a VFP FRX Report without a User Interface for
example on a Web Server, you can use the Mind's Eye Report Engine to quickly
generate reports and return them over the web or email them to users.
SET
CLASSLIB TO MindsEyeReportEngine
oReportEngine = CREATEOBJECT('MindsEyeReportEngine')
PUBLIC oRPT
oRPT =
oReportEngine.ReportFormObject('SomeReport.FRX')
oRPT.oReportEngine.SaveToPDF('SomeReport.PDF')
&& Saves
the report to a PDF document
oRPT.oReportEngine.PrintReport()
&& Prints to the Currently Selected Printer
oRPT.oReportEngine.PrintReport(GETPRINTER())
&& Uses Printer
Name from the VFP GETPRINTER() Function
*
NOW EMAIL THE REPORT WITHOUT ANY USER INTERFACE
WITH oRPT.oReportEngine
.EMAILMessagingType
= 0
&& SMTP = 0, MAPI = 1
.EMAILSMTPHost
= 'yourSMTPhost.com'
.EMAILRecipients
= 'someone@hotmail.com'
.EMAILFromAddress = 'me@hotmail.com'
.EMAILBody
= 'This is the body text for the email message'
.EMAIKSubject = 'EMAIL
Subject goes here!'
.EMAILAttachmentFileName =
'My Report.PDF'
.SendMail()
&& NOW SEND THE
EMAIL USING THE SENDMAIL METHOD
ENDWITH
oRPT =
NULL
Report Engine Object Speed
The following example
demonstrates using the Mind's Eye Report Engine without using an FRX Report.
This example adds 1000 pages into the Report Engine using the
NewPageByPaperSize() Method and sets the WatermarkText and
WatermarkRotationAngle Properties for each of those pages. Then after it has
created the 1000 pages and set the Watermark Properties, it uses the GoToPage()
Method to display all of the pages in the Report Engine.
SET
CLASSLIB TO MindsEyeReportPreviewForms
PUBLIC oRPT
oRPT =
CREATEOBJECT('MindsEyeReportPreviewForm')
FOR i = 1 TO 999
WITH
oRPT.oReportEngine
.WatermarkText = 'Draft Copy'
.WatermarkRotationAngle = i
.NewPageByPaperSize(1)
ENDWITH
ENDFOR
oRPT.oReportEngine.WatermarkText = 'Draft
Copy'
oRPT.SHOW()
* Now
just for fun demonstrate that each page actually has it's own Watermark
Properties
FOR i
= 1 TO oRPT.oReportEngine.nTotalPages oRPT.oReportEngine.GotoPage(i) ENDFOR
Placing Charts into the Report Engine
The Mind's Eye Report
Engine has a built in Charting Engine, so that charts can be added to your
reports to be printed or saved to PDF files. The following example demonstrates
how to programmatically generate a Chart within the Report Engine:
SET
CLASSLIB TO MindsEyeReportPreviewForms PUBLIC oRPT oRPT = CREATEOBJECT('mindseyereportpreviewform') oRPT.Top = 10 oRPT.Left = 20 oRPT.Width = 600 oRPT.Height = 800
WITH
oRPT.oReportEngine .AddChart('',1,1,1,6,5)
.ChartSeriesTitle = 'Portfolio' .ChartSeriesColor = 16744576 .ChartAddXYData(4.8,0,'Sep 02',16744576)
.ChartAddXYData(4.1,0,'Dec 02',16744576)
.ChartAddXYData(3.8,0,'Mar 03',16744576) .ChartAddXYData(3.4,0,'Jun 03',16744576) .ChartAddSeries(1,'Index 1',4194432) .ChartAddXYData(4.2,0,'Sep 02',4194432) .ChartAddXYData(3.8,0,'Dec 02',4194432) .ChartAddXYData(3.5,0,'Mar 03',4194432) .ChartAddXYData(3.1,0,'Jun 03',4194432) .ChartAddSeries(1,'Index 2',14089977) .ChartAddXYData(3.6,0,'Sep 02',14089977) .ChartAddXYData(3.2,0,'Dec 02',14089977) .ChartAddXYData(2.7,0,'Mar 03',14089977) .ChartAddXYData(2.5,0,'Jun 03',14089977) .ChartTitle = 'Portfolio VS Benchmark' .ChartXAxisTitle = 'Period' .ChartXAxisFontSize = 16 .ChartYAxisTitle = 'Return' .ChartYAxisFontSize = 16 .ChartSeriesMarksVisible = .f. ENDWITH
oRPT.Show()
Specifying the Printer Tray for Individual Pages
Each page in the Report
Engine can be pulled from a different tray automatically while printing by
assigning the PAPERBIN Property to a specific bin number. The PAPERBIN values
are the same as those described in the WINDOWS.H Header File. The following example
demonstrates how to assign the Printer Tray for each individual page in a Report
using the PAPERBIN Property. Please note that not all printers support all of
the values since each printer may not have all the trays that can possibly be
specified by the values below. However, you can loop through the pages in the
report engine and assign the PAPERBIN property for each and every page. For
example, if you wanted the first page to be printed onto Letterhead that is
placed in the LOWER TRAY, then set the PAPERBIN Property to 2 for the first page
in the report engine. All other PAPERBIN values will be set to 0 and will be
pulled from the AUTO tray unless specified otherwise.
DMBIN_UPPER = 1
DMBIN_FIRST = DMBIN_UPPER
DMBIN_ONLYONE = 1
DMBIN_LOWER = 2
DMBIN_MIDDLE = 3
DMBIN_MANUAL = 4
DMBIN_ENVELOPE = 5
DMBIN_ENVMANUAL = 6
DMBIN_AUTO = 7
DMBIN_TRACTOR = 8
DMBIN_SMALLFMT = 9
DMBIN_LARGEFMT = 10
DMBIN_LARGECAPACITY = 11
DMBIN_CASSETTE = 14
DMBIN_LAST = DMBIN_CASSETTE
DMBIN_USER = 256 (Values that are 256 and above are User Defined and vary by
printer)
SET
CLASSLIB TO MindsEyeReportPreviewForms
PUBLIC oRPT
oRPT =
CREATEOBJECT('MindsEyeReportPreviewForm')
WITH oRPT.oReportEngine
.WatermarkText = 'LOWER TRAY'
.PAPERBIN = 2
&& DMBIN_LOWER
.NewPageByPaperSize(1)
.WatermarkText = 'DEFAULT TRAY'
.NewPageByPaperSize(1)
.WatermarkText = 'MANUAL FEED'
.PAPERBIN = 4
&& DMBIN_MANUAL
.FirstPage()
ENDWITH
oRPT.SHOW()
* Now
call the PrintReport Method to print the pages.
oRPT.oReportEngine.PrintReport()
|