170 likes | 353 Views
Using the Crystal RDC Interface in Visual DataFlex. John J Tuohy Data Access Worldwide. What does the Crystal class do?. Allows you to run a Crystal Report from within your VDF Application At the most basic level you want to select a report and run it
E N D
Using the Crystal RDC Interface in Visual DataFlex John J Tuohy Data Access Worldwide
What does the Crystal class do? • Allows you to run a Crystal Report from within your VDF Application • At the most basic level you want to select a report and run it • Just select a Report, select an output destination and run it • In more advanced cases you want to dynamically change the report at runtime • Change the sort order • Change record and group selection formulas • Change formula and parameter values • Change tables being used in a report • Generate and use dynamic (non-table based) data
How the current Crystal class works • CrystalReport class • Based on crpe32.dll API • Can be distributed royalty free • Implemented using VDF’s External_functions • Uses a flat Interface which passes complex data • Works great
Why do we need to change this? • Business Objects / Crystal really wants you to stop using it! • As of Crystal Reports XI • It is no longer supported • Crystal XI claims it’s not even there (it is) • It is very old technology that will not be updated or fixed • It has been replaced with their RDC API
How does the new interface work? • Based on their Report Design Component (RDC) API • RDC is a COM interface • Imported via FlexCom2 • Uses • Craxddrt.dll – automation library • CRViewer.dll – activeX Report viewer • CDO32.dll – automation library • Can be distributed royalty free • Uses the RDC object model • Lots of objects with simple interfaces
Implementation plans • Provide a new class, cCrystal, which will wrap all of the RDC COM objects • Make it easy to get at the most commonly needed COM objects • Simplify the object aggregation process • Use the standard RDC object model and interface • Provide a simple way to view reports within an application • Provide helper interfaces to make it easy to do the most commonly required tasks • For more complicated tasks, provide good samples to show how to do it. • Get out of the way!
What are the benefits of using the new class? • You are up to date • You have more features at your disposal (e.g. CDO) • You are using the industry standard method for working with Crystal • This lets you use the Crystal Documentation, Crystal Newsgroups, etc. to get development assistance. • Once you “get it”, it's not that hard • The skills you learn can be applied to other COM solutions
Compatibility issues • The new class is not designed to be compatible with the old class • You can still use CRPE32 for your old reports • Options we are considering for providing a “compatibility layer” • None at all • Could provide a limited compatibility layer • Could provide a complete compatibility layer • Give us your feedback on this issue.
The new class structure/interface • cCrystal class • Property Integer peOutputDestination • Property String psReportName • Procedure RunReport • Procedure OnInitializeReport handle hoReport • Procedure PrintReport handle hoReport • Procedure PreviewReport handle hoReport • Procedure ExportReport handle hoReport
Samples: Print to viewer // // Simple Print (default is print to preview) // Object oCrystalReport is a cCrystal Set psReportName to "CustLst.rpt" End_Object
Samples: Select output destination Object oCrystalReport is a cCrystal Set psReportName to "CustLst.rpt" End_Object Object oPrintToScreen is a Button Procedure OnClick Set peOutputDestination of oCrystalReport to PRINT_TO_WINDOW Send RunReport of oCrystalReport End_Procedure End_Object Object oPrintToExport is a Button Procedure OnClick Set peOutputDestination of oCrystalReport to PRINT_TO_FILE Send RunReport of oCrystalReport End_Procedure End_Object
Samples: Select printer via prompt Object oCrystalReport is a cCrystal Set psReportName to "CustLst.rpt" Procedure OnInitializeReport Handle hoReport Forward Send OnInitializeReport hoReport End_Procedure Procedure PrintReport handle hoReport Set piPrinterPrompt of hoReport to True End_Procedure End_Object Object oButton1 is a Button Procedure OnClick Set peOutputDestination of oCrystalReport to PRINT_TO_PRINTER Send RunReport of oCrystalReport End_Procedure End_Object
Samples: Output to predefined printer Object oCrystalReport is a cCrystal Set psReportName to "CustLst.rpt" Set peOutputDestination of oCrystalReport to PRINT_TO_PRINTER Procedure OnInitializeReport Handle hoReport Forward Send OnInitializeReport hoReport End_Procedure Procedure PrintReport Handle hoReport Send ComSelectPrinter of hoReport "winspool" "Lexmark 3320" "LPT1:" Set ComPaperOrientation of hoReport to crLandscape Set ComPaperSize of hoReport to crPaperLetter Set piPrinterCopies of hoReport to 2 Set pbPrinterCollate of hoReport to FALSE Forward Send PrintReport hoReport End_Procedure End_Object
Samples: Output to MAPI – no prompt Object oCrystalReport is a cCrystal Set psReportName to "CustLst.rpt" Set peDestination to Print_to_File Procedure ExportReport Handle hoReport Handle hoExport Get ExportObject of hoReport to hoExport Set pbPromptExport of hoReport to False Set ComDestinationType of hoExport to crEDTEMailMAPI Set ComMailToList of hoExport to "someoneelse@hotmail.com" Set ComMailSubject of hoExport to "Testing" Set ComMailMessage of hoExport to "This is a test" Set ComExportFileName of hoExport to "MyReport.pdf" Set ComFormatType of hoExport to crEFTPortableDocFormat Forward Send ExportReport hoReport End_Procedure End_Object
Samples: Assign selections, formulas and sorts Object oCrystalReport is a cCrystal Set psReportName to "CustLst.rpt" Procedure OnInitializeReport Handle hoReport : // set record selection formula Get Value of oForm1 to sState Set ComRecordSelectionFormula of hoReport to ('{Cust.State}="' * sState * '"}') // set a formula Send AssignFormula of hoReport "Company Name" '"Data Access Corporation"' // assign a sort order Send DeleteSortOrder of hoReport Send AppendSortField of hoReport "Cust" "State" crAscendingOrder Send AppendSortField of hoReport "Cust" "Name" crDescendingOrder End_Procedure End_Object
Samples: Using CDO (dynamic data sources) Object oReport is a cCrystal Set psReportName To "PercentageFilled.rpt" Procedure OnInitializeReport Handle hoReport Handle hoCDO Integer iItem Variant[][3] vData Forward Send OnInitializeReport hoReport Get CreateCDO of hoReport "Stuff.ttx" to hoCDO If hoCDO begin Direct_input "c:MyListOfStuf" While (not(SeqEof)) Readln vData[iItem][0], vData[iItem][1], vData[iItem][2] Increment iItem End // Add rows to CDO object Send ComAddRows of hoCDO vData End End_Procedure // OnInitializeReport End_Object // oReport
Samples: Using CDO with Code Validation Tables Object oReport is a cCrystal Set psReportName To "PercentageFilled.rpt" Procedure OnInitializeReport Handle hoReport Handle hoCDO Variant[][2] vData Forward Send OnInitializeReport hoReport Get CreateCDO of hoReport "States.ttx" to hoCDO Get TableData of Customer_State_VT to vData Send ComAddRows of hoCDO vData End_Procedure // OnInitializeReport End_Object // oReport