Data Access Worldwide Knowledge Base

Article ID 2192
Article Title EXAMPLE: Use Crystal to print information from the filelist
Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2192
KBase Category VDF11
Date Created 11/19/2005
Last Edit Date 11/23/2005


Article Text
QUESTION:
Can I use Crystal Reports to print my filelist information?

ANSWER:
You can do this but not directly from within Crystal because the DataFlex filelist is not an embedded database table nor a file that is accessible via ODBC. To print the information, you need to use CDO. CDO is an abbreviation for Crystal Data Objects. With this technique your fat client application (like Visual DataFlex) creates an array of information in memory and Crystal accesses this array as if it were a table with information. CDO is a great technique to have control over what data is going be printed and you can, for example, use it to flag invoices as printed after the printing was completed. Without CDO you would not have a clue what was selected and printed.

How to do this?

- Start Crystal XI
- Create a new report
- Create a new connection and instead of choosing DataFlex or an ODBC/SQL datasource, you select "Field Definitions Only"
- In the popup dialog press the button "Create file"
- In the next popup dialog you setup the layout of a TTX file. This is the description of the in memory array with data. How many fields, what type, what length.
- Add fields "RootName", "DisplayName", "LogicalName" and "Filenumber"
- Save the definition under a name like Filelist.Ttx
- Use the fields from this datasource in the body section of the report. If you entered a default value per field in the TTX definition, you will see this data when you run the preview.
- Save the report to disk. Make sure the "save data with report" flag is turned off. If it is not turned off, the passed data from the array will not be used.

The attached example shows you how to use a TTX.

- Start the Visual DataFlex 11.1 Studio -- You need 11.1 because this has the Crystal RDC classes and easy support for CDO.
- Create a new report view
- Drag a Crystal report (class cCrystal) object from the controls palette to the report view
- Add a button to the report view to start the report. The OnClick procedure should send the message RunReport to the cCrystal report
- In the procedure OnInitializeReport add the following code:

    Integer iFile iCount
    Variant[][4] vFileListData

    Get_Attribute DF_FILE_NEXT_USED Of iFile To iFile
    While (iFile > 0)
        Get_Attribute DF_FILE_ROOT_NAME Of iFile To vFileListData[iCount][0]
        Get_Attribute DF_FILE_DISPLAY_NAME Of iFile To vFileListData[iCount][1]
        Get_Attribute DF_FILE_LOGICAL_NAME Of iFile To vFileListData[iCount][2]
        Move iFile To vFileListData[iCount][3]

        Get_Attribute DF_FILE_NEXT_USED Of iFile To iFile
        Increment iCount
    Loop

    If (SizeOfArray (vFileListData) > 0) Begin
        Get CreateCDO Of hoReport "FileList.ttx" To hoCDO
        If (hoCDO > 0) Begin
            Send AppendCDOData Of hoReport hoCDO vFileListData
        End
    End

Notes:
- If your TTX file is not named Filelist.TTX, change the name in the above code.
- The CDO connection in our Visual DataFlex classes require the table in the report to have the same name as the TTX file without the TTX extension.

READY?
Yes, with this you can print the filelist information. But take a look at the enclosed finished reportview if you want a bit more like printing the name (location) of the filelist, skipping the tables whose display name starts with a '@' sign or skipping tables in the Data Access reserved area of the filelist.



Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu

Web Links Related to this Article
File FilelistReport.zip
URL=http://www.dataaccess.com/KBasePublic/Files/2192.FilelistReport.zip

File PrintFileList.zip
URL=http://www.dataaccess.com/KBasePublic/Files/2192.PrintFileList.zip


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.