Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 Using the Crystal RDC Interface in Visual DataFlex John J Tuohy Data Access Worldwide
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 What does the Crystal class do in VDF? 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
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 How the old 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
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 Why does VDF need to change? Business Objects wants to end the use of CRPE32.DLL-based technology As of Crystal Reports XI CRPE32.DLL 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
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 How does the new interface work? Based on Crystal’s 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
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 Implementation in VDF 11.1 A new class, cCrystal, wraps all of the RDC COM objects Makes it easy to get at the most commonly needed COM objects Simplify the object aggregation process Uses the standard RDC object model and interface Provides a simple way to view reports within an application Provides 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!
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 What are the benefits of using the new class? Uses up to date, supported Crystal interface You have more features at your disposal (e.g. CDO) You are using the industry standard method for working with Crystal 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
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 Compatibility issues The new, VDF 11.1 cCrystal class is not designed to be compatible with the old CrystalReport class You can still use CRPE32.DLL for your old/existing reports with Crystal Reports XI and older Business Objects may remove CRPE32.DLL from future releases (consider it likely) You can use Crystal XI to transition to the new RDC technology
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 The new class structure/interface cCrystal class Property: Integer peOutputDestination Property: String psReportName Procedure: RunReport Event: OnInitializeReport handle hoReport Event: OnPrintReport handle hoReport Event: OnPreviewReport handle hoReport Event: OnExportReport handle hoReport
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 Samples: Print to viewer // // Simple Print (default is print to preview) // Object oCrystalReport is a cCrystal Set psReportName to "CustLst.rpt" End_Object
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 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
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 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 OnPrintReport handle hoReport Forward Send OnPrintReport 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
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 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 OnPrintReport Handle hoReport Forward Send OnPrintReport hoReport Send ComSelectPrinterof hoReport "winspool" "Lexmark 3320" "LPT1:" Set ComPaperOrientationof hoReport to crLandscape Set ComPaperSizeof hoReport to crPaperLetter Set piPrinterCopiesof hoReport to 2 Set pbPrinterCollateof hoReport to FALSE End_Procedure End_Object
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 Samples: Output to MAPI – no prompt Object oCrystalReport is a cCrystal Set psReportName to "CustLst.rpt" Set peDestination to Print_to_File Procedure OnExportReport Handle hoReport Handle hoExport Forward Send OnExportReport hoReport Get ExportObject of hoReport to hoExport Set pbPromptExportof hoReport to False Set ComDestinationTypeof hoExport to crEDT MAPI Set ComMailToListof hoExport to Set ComMailSubjectof hoExport to "Testing" Set ComMailMessageof hoExport to "This is a test" Set ComExportFileNameof hoExport to "MyReport.pdf" Set ComFormatTypeof hoExport to crEFTPortableDocFormat End_Procedure End_Object
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 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
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 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:MyListOfStuff" While (not(SeqEof)) Readln vData[iItem][0], vData[iItem][1], vData[iItem][2] Increment iItem End // Add rows to CDO object Send AppendCDOData of hoReport hoCDO vData End End_Procedure // OnInitializeReport End_Object // oReport
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide Meet Me In Saint Louis October 14-15, 2005 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 AppendCDOData of hoReport hoCDO vData End_Procedure // OnInitializeReport End_Object // oReport