Using Flex2Crystal in Windows Apps¶
Follow the procedures below to modify an existing DataFlex Windows application to work with the latest version of Crystal Reports.
Add the Flex2Crystal Library to Your Workspace¶
Flex2Crystal is installed as a DataFlex Library installed in the <User Documents>\Mertech Data Systems\Flex2Crystal\lib folder. This library needs to be included in your workspace or, in older versions of DataFlex, added to you workspace compile path.
Start DataFlex Studio.
Open the current workspace.
Selectfrom the DataFlex menu bar. Existing library paths (if any) are displayed in the Library Maintenance dialog box.
Click Add Library.
Navigate to the
User Documents\Mertech Data Systems\Flex2Crystal\lib folder.
Flex2Crystal.sws, then click Open.
A confirmation dialog box prompts to add the library using relative pathing (Yes) or absolute pathing (No). It is recommended that you select Yes. The Library Maintenance dialog box shows the addition of the Flex2Crystal library.
You can selectfrom the DataFlex menu bar to verify that the Flex2Crystal library was added to the library paths.
The library name and location have changed from prior builds. You need to update any workspaces that reference the Flex2Crystal library to point to the library (Flex2Crystal.sws) in the new location (under
Update Your Report View Files¶
A few simple search and replace operations in your report view (.rv) files are all that is required to run your existing reports with Crystal Reports version 2016.
Open your report view files in DataFlex Studio.
Change the include files.
To include the new Flex2Crystal class and object definitions and to verify that the Flex2Crystal components are properly installed, perform the replacement shown below.
Connect to Flex2Crystal.
To use the new Flex2Crystal class definitions, replace all occurrences of
cFlex2Crystal. Examples are shown below.
For example, replace
The order in which Use packages appear in a program is important. So, if for example,
Use Crystal\\CheckForCrystal.dg appears in a view (.vw) file, which is included in the program before a report view file, the new Flex2Crystal dialog box will not be loaded.
Compile and run your program.
A Sample Migration¶
Code extracted from the
OrdersByCustomerCR.rv example is shown below. The only changes required to make this code work with Crystal Reports version 2016 are:
cCrystalclasses should be changed to their cFlex2Crystal equivalent)
Use CheckForFlex2Crystal.dg Use dfrptvw.pkg Use dfRadio.pkg Use Windows.pkg Use cFlex2Crystal.pkg Deferred_view Activate_oOrdersByCustomerCR for ; ; Object oOrdersByCustomerCR is a ReportView Set Label to "Orders by Customer" Set Location to 2 23 Set Size to 72 185 Set piMinSize to 72 185 . . . Object oRunButton is a Button Set Label to "Run Report" Set Size to 14 53 Set Location to 20 122 Set Default_State to True Procedure OnClick Boolean bReportOK bCrystalOK String sReportName Get CheckCrystalEnvironment of oCheckForFlex2Crystal to bCrystalOK If (bCrystalOK) Begin Set psReportName of oCrystalReport to "..\Data\Flex2Crystal.rpt" Send RunReport of oCrystalReport End Else Begin Send DisplayDialog of oCheckForFlex2Crystal End End_Procedure End_Object // oRunButton . . . Object oCrystalReport1 is a cFlex2Crystal Procedure MakeSectionsInvisible integer eSectionType Integer iGroup Handle hoReport Handle hoAreas hoArea Variant vAreas vArea Integer iAreas iArea iKind Get ReportObject to hoReport Get Create of hoReport U_cFlex2CrystalAreas to hoAreas // areas collection Get Create of hoReport U_cFlex2CrystalArea to hoArea // area object . . .
Creating a New Report¶
Flex2Crystal installs two workspaces that include reports that can be used as templates for creating new reports. The Flex2Crystal library contains
ReportPreviewCR.rv, which shows how to use CDOs and ADOs in a report (see Using the CDO Interface and Using the ADO.NET Interface ). The Mertech Example Application workspace contains a report template and two sample reports that can be used as guides to create other reports.
All the reports include the
cFlex2Crystal.pkg and have a call to
CheckCrystalEnvironment in the