DEFINE CLASS cfrmCrystal AS form Caption = 'Report Preview' oCrystalReports = NULL oReport = NULL oDB = NULL oCDBT = NULL oDBT = NULL oExp = NULL cTableName = "" cReportName = "" cP2FName = "" nCopies = 1 WindowState = 2 && Maximized WindowType = 1 && Modal Dialog Closable = .t. nOrient = 1 lP2F = .F. PROCEDURE Init(tcReportName AS String, ; tcTableName AS String, ; tnCopies AS Integer, ; tcFormCaption AS String, ; tlP2F AS Logical, ; tcP2FName AS String, ; tnOrient as Integer ; ) AS Boolean _VFP.AutoYield = .F. && We're hosting an ActiveX control in a form, so... WITH Thisform IF VARTYPE(tcReportName) = "C" .cReportName = tcReportName ENDIF IF VARTYPE(tcTableName) = "C" .cTableName = tcTableName ENDIF IF VARTYPE(tnCopies) = "N" .nCopies = tnCopies ENDIF IF VARTYPE(tcFormCaption) = "C" .Caption = tcFormCaption ENDIF IF VARTYPE(tlP2F) = "L" .lP2F = tlP2F ENDIF IF VARTYPE(tcP2FName) = "C" .cP2FName = tcP2FName ENDIF IF VARTYPE(tnOrient) = "N" .nOrient = tnOrient ENDIF .closable = .t. ENDWITH ENDPROC PROCEDURE BuildCRObjects WITH Thisform .oCrystalReports = CREATEOBJECT("CrystalRuntime.Application") .oReport = .oCrystalReports.OpenReport(.cReportName) .oDB = .oReport.Database .oCDBT = .oDB.Tables() .oDBT = .oCDBT.Item(1) .oDB.Verify() .oDBT.SetTableLocation(.cTableName,JUSTFNAME(.cTableName),"") =VFPDelay(2) .oDB.Verify() IF FILE('Crystal.txt') NAME1 = .oDBT.name .oDBT.name = XXX MESSAGEBOX("Please record the following: " + CHR(13) + CHR(13) + ; "DLL Name = " + .oDBT.dllname + CHR(13) + ; "Name1 = " + name1 + CHR(13) + ; "Name = " + .oDBT.name + CHR(13) + ; "Location = " + .oDBT.location + CHR(13),0) ENDIF IF .oReport.HasSavedData .oReport.DiscardSavedData() ENDIF lnNumPrint = APRINTERS(laPrinters) IF lnNumPrint > 0 FOR ii = 1 TO lnNumPrint IF SET("PRINTER",3) = UPPER(laPrinters(ii,1)) .oReport.SelectPrinter(.oReport.DriverName,SET("PRINTER",3),laPrinters(ii,2)) EXIT ENDIF ENDFOR ELSE =GETCHOIC('There are no printing devices attached to this computer.','OK') ENDIF .oReport.PaperOrientation = .nOrient ENDWITH ENDPROC PROCEDURE DoPreview WITH Thisform ASSERT NOT EMPTY(.cReportName) MESSAGE ; [Report name has not been set.] ASSERT NOT EMPTY(.cTableName) MESSAGE ; [Table name has not been set.] .BuildCRObjects() .AddObject("oleCRViewer", "oleControl", "crViewer.crViewer") ENDWITH WITH Thisform.oleCRViewer * Set report viewer Properties. .DisplayGroupTree = .F. .DisplayTabs = .F. .EnableDrillDown = .F. .EnableExportButton = .F. .EnableGroupTree = .F. .EnableHelpButton = .F. .EnableNavigationControls = .T. .EnablePopupMenu = .F. .EnablePrintButton = .F. .EnableRefreshButton = .F. .EnableSearchControl = .F. .EnableStopButton = .F. .EnableZoomControl = .T. .EnableCloseButton = .T. .ReportSource = Thisform.oReport .ViewReport() ENDWITH Thisform.Show() ENDPROC PROCEDURE DoPrint WITH Thisform ASSERT NOT EMPTY(.cReportName) MESSAGE ; [Report name has not been set.] ASSERT NOT EMPTY(.cTableName) MESSAGE ; [Table name has not been set.] ASSERT .nCopies > 0 MESSAGE ; [Number of copies must be an integer 1 or higher.] .BuildCRObjects() IF .lP2F .oExp = .oReport.ExportOptions() .oExp.DestinationType = 1 .oExp.FormatType = 31 && PDF Format .oExp.DiskFileName = .cP2FName .oReport.Export(.F.) ELSE .oReport.Printout(.F., .nCopies) ENDIF ENDWITH ENDPROC PROCEDURE Error LPARAMETERS nError, cMethod, nLine IF nError != 1440 DODEFAULT() ENDIF ENDPROC PROCEDURE Resize WITH This .oleCRViewer.Top = 1 .oleCRViewer.Left = 1 .oleCRViewer.Height = .Height - 2 .oleCRViewer.Width = .Width - 2 ENDWITH ENDPROC PROCEDURE Load SYS(2333,1) ENDPROC PROCEDURE Activate WITH This.oleCRViewer .Top = 5 .Left = 5 .Height = ThisForm.Height - 2 .Width = ThisForm.Width - 2 ENDWITH ThisForm.Resize() ENDPROC *- If passed report does not have an extension, assign "RPT" to it. PROCEDURE cReportName_Assign(tcValue AS String) AS TextBox IF EMPTY(JUSTEXT(tcValue)) tcValue = FORCEEXT(tcValue, "RPT") ENDIF This.cReportName = tcValue RETURN This.cReportName ENDPROC *- If passed table does not have an extension, assign "DBF" to it. PROCEDURE cTableName_Assign(tcValue AS String) AS TextBox IF EMPTY(JUSTEXT(tcValue)) tcValue = FORCEEXT(tcValue, "DBF") ENDIF This.cTableName = tcValue RETURN This.cTableName ENDPROC PROCEDURE Destroy WITH This .Deactivate() .oExp = NULL .oDBT = NULL .oCDBT = NULL .oDB = NULL .oReport = NULL .oCrystalReports = NULL *-- This object only exists if DoPreview() has been called IF PEMSTATUS(This,"oleCRViewer", 5) .oleCRViewer = NULL .RemoveObject("oleCRViewer") ENDIF ENDWITH ENDPROC PROCEDURE Release IF PEMSTATUS(Thisform,"oleCRViewer", 5) thisform.oleCRViewer = NULL ENDIF ENDPROC ENDDEFINE>>