Subscribe to our YouTube Channel for more Videos

How to use crystal reports in delphi 7 ?


Are you looking at the tutorial on how to integrate crystal reports in delphi 7 , here’ a blog post that explains with step by step instructions on how you can do it.

crystal reports in delphi 7

How to use crystal reports in delphi 7 ?

To include the RDC runtime library into Delphi, start a new project in Delphi and follow these steps:

1. Select the Project menu and then the Import Type Library.

2. In the Import Type Library, Select Crystal Report x ActiveX Designer Runtime Library and rename the TReport and TDatabase class names to CRReport and TCRDatabase to aoid the naming conflicts

3. Click the Install button, then click the Into New Package tab,provide a file name path for the new package and select ok.

4. In the Confirm box, click Yes On Delphi’s ActiveX tab, there is now an Application object icon and CRReport object icon.

5. From Delphi’s ActiveX tab, place an Application object onto Form1. This adds OleServer and CRAXDRT_TLB to the Uses clause on Form1.

To work with RDC , we now require Report Object and the Application Object

1. Declare the report object and the Application Object
Eg :

report : IReport;

2. Open the report using the Application’s OpenReport function

report := Application1.OpenReport(‘c:\senthilreport.rpt’,crOpenReportByTempCopy);

The first parameter to the OpenReport function is the path of the report file .The second parameter’s description is as follows

1. The CrOpenReportByDefault locks the RPT file preventing it from being accessed by other users.

2. CrOpenReportByTempCopy opens a temporary copy of the RPT file.

Next we need to Add the Crystal Report Viewer Control to access the data in the Report .

To include the CRViewer into your project:

1. Select the Project menu and Import Type Library.

2. Select Crystal Reports Viewer Control and click the Install button. The CRViewer control is added to Delphi’s ActiveX tab.

3. Add the CRViewer control to Form1.

Set the ReportSource to the report created using the OpenReport function .

crViewer1.ReportSource := report; 
crViewer1.ViewReport;

You should see the Crystal Report viewer with the Data once you run the Project .

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.