delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (30)


Using Automation with Crystal Reports and DelphiFormat this article printer-friendly!Bookmark function is only available for registered users!
Previewing reports using the CRViewer ActiveX control
Product:
Delphi 4.x (or higher)
Category:
Reporting
Skill Level:
Scoring:
Last Update:
05/04/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet Crystal Reports Report Reporting Seagate Crystal Descisions Automation RDC CRViewer ActiveX
Times Scored:
41
Visits:
38860
Uploader: Jeff Guidotti
Company:
Reference: Crystal Decisions - Crystal Reports - Web Site
 
Question/Problem/Abstract:
This article should help you get started using the automation features of Crystal Reports 8.0+ in Delphi.
Answer:



In order to use the automation features in Crystal Reports 8.0 and higher, you must first import the type libraries into Delphi.

1. From the Delphi IDE main menu, go to Project | Import Type Libary.
2. Highlight 'Crystal Report 8 Active X Designer Run Time Libary'.
3. In the Class Names box, change the following items (TReport and TDatabase
   conflict with standard Delphi components):
      TReport   >>> change to >>> TCrReport
      TDatabase >>> change to >>> TCrDatabase
4. Change the Palette page to Crystal Reports
5. Click 'Generate Component Wrapper'
6. Click 'Install...'
7. Click the Into New Package tab.
8. Click 'Browse', select a destination directory for the new package, enter.
   the filename 'CR_AUTO.DPK', then click the 'Open' button.
9. Enter the description 'Crystal Reports Automation Server' (or another one
   if you like), and click the 'OK' button.
10. At the confirmation box 'Package CR_AUTO.bpl will be built then installed.
   Continue?' choose 'No'.
11. Go back to the main menu and choose Project | Import Type Library.
12. This time choose the 'Crystal Report Viewer Control'.
13. Change the Palette page to Crystal Reports
14. Click 'Generate Component Wrapper'
15. Click 'Install...'
16. Click the Into Existing Package tab.
17. Browse or Select the 'CR_AUTO.DPK' package we created earlier.
18. Click 'OK'
19. This time the install confirmation box, click 'Yes'.
20. A message will appear notifying you that the following components have
    been registered: TApplication, TCRField, TCRFields, TCrReport,
    CRVEventInfo, TCRViewer, TCRVTrackCursorInfo, TReportSourceRouter.
    Click 'OK'
21. Save and Close the package.
22. We have now imported the appropriate type libraries and are ready to
    build a test application.

NOTE: Importing the Crystal Report Run Time Library registers a component TApplication.  This will conflict with TApplication - the Delphi standard component.  If you need to access the original TApplication in a form where you are using the Crystal Reports Server components or Crystal Reports viewer, you can access it as: Forms.Application.

-------------------------------------------------------------------------------

Next you must create a sample report in Crystal Reports to work with.  For purposes of this example, make a very simple report just until you are comfortable with the process, then expand on it from there.

Save this report to 'C:\MyReport.rpt'.

-------------------------------------------------------------------------------

Next let's setup the sample application:

1. In Delphi, create a New Application.
2. From the Crystal Reports tab drop an Application component onto the form
   and rename it 'CrystalApp'.
3. Next drop a CrReport component onto the form and rename it 'CrystalRpt'.
4. Finally drop a CRViewer component onto the form, rename it 'CrystalView',
   and change the align probably to alClient.
5. In the FormCreate procedure for the form, enter the following:

      CrystalApp.LogOnServer();   { <<<<<<<<<<<  SEE NOTES BELOW }
      CrystalRpt.ConnectTo(CrystalApp.OpenReport('C:\MyReport.rpt'));
      CrystalView.ReportSource := CrystalReport.DefaultInterface;
      CrystalView.ViewReport;


   The CrystalApp.LogOnServer call can take a wide variety of input depending
   on how you are connecting to the database used in your report.  The
   following is an excerpt from Crystal Reports Developer Help File:

   Syntax
   ------
   LogOnServer ( pDllName As String, pServerName As String, [pDatabaseName],
                 [pUserID], [pPassword] )


   Parameters      Description
   ----------      ------------------------------------------------------------
   pDllName        Specifies the name of the DLL for the server or password
                   protected non-SQL table you want to log on to, for
                   example "PDSODBC.DLL". Note that the dllName must be
                   enclosed in quotes. DLL names have the following naming
                   convention: PDB*.DLL for standard (non-SQL) databases,
                   PDS*.DLL for SQL/ODBC databases.  Specifies the name of
                   the DLL for the server or password protected non-SQL table
                   you want to log on to, for example "PDSODBC.DLL". Note that
                   the dllName must be enclosed in quotes. DLL names have the
                   following naming convention: PDB*.DLL for standard
                   (non-SQL)databases, PDS*.DLL for SQL/ODBC databases.

  pServerName      Specifies the log on name for the server used to create the
                   report. For ODBC, use the data source name. This value is
                   case-sensitive. See Remarks below.

  [pDatabaseName]  Specifies the name for the database used to create the
                   report. See Remarks below.

  [pUserID]        Specifies the User ID number necessary to log on to the
                   server. See Remarks below.

  [pPassword]      Specifies the password necessary to log on to the server.
 

  Remarks
  -------
  When you pass an empty string ("") for this parameter, the program uses the
  value that's already set in the report. If you want to override a value
  that's already set in the report, use a non-empty string (for
  example, "Server A").


NOTE: For an easy way to determine what your correct LogOnServer server is, open the report in Crystal Reports, and from the main menu go to Database | Set
Location.  The location screen will show you the settings for Server Type, Server Name, Database, and User ID.

NOTE: For an easy way to determine the correct dllName to use, open the report in Crystal Reports, and from the main menu go to Database | Convert Database Driver.  From the Convert Database Driver window, place a checkmark in the box 'Convert Database Driver on next Refresh'.  Your dllName is listed next to From.  CLICK CANCEL WHEN CLOSING THIS WINDOW SO YOU DO NOT ACTUALLY CHANGE THE DATABASE DRIVER!

I connect to a password protected Microsoft Access 97 database and use the
following format.

     LogOnServer('pdsodbc.dll','MyDSN.dsn','','DB_Username','DB_Password');

NOTE: For those unfamiliar with ODBC, the DSN is setup through ODBC Data Sources in Windows Control Panel, and contains the database type, location, system database, and additional logon info.

You may have to experiment around a bit to get the LogOnServer funciton working for your connectivity needs.  Reference the help file Developr.hlp in the Seagate Software directory for assistance.

That's ALL there is to it!  





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
ddd
    sedat grr (Jan 9 2010 10:05AM)

dddeswþfksþfdþafs afþkaþfskaiþd asdaksdakd
Respond

Modify Query
    ahmad behjati (Oct 15 2008 8:28AM)

How can I modify queries for each table in my report? Such as adding a condition without changing fields.
Respond

Help me !
    Tran Van Huy (Apr 7 2006 5:53AM)

I want to use Crystal Report 9 in Delphi.net But I can't add class of the Crystal R into Delphi. Please, tell me about it !
Thanks !
Respond

SQL Server
    Avi Singh (Nov 22 2005 9:26AM)

Im trying to connect my report to me database but i keep getting the 'Server not opened' message.

Application1.LogOnServer('pdsodbc.dll','TECHNO3',,,);
      crReport := Application1.OpenReport('G:\Data\epics\reports\LdSchDet.rpt',crOpenReportByTempCopy);
      crReport.ExportOptions.FormatType := CRAXDRT_TLB.crEFTPortableDocFormat;
      crReport.ExportOptions.DestinationType := CRAXDRT_TLB.crEDTDiskFile;
      crReport.ExportOptions.DiskFileName := 'c:\p.pdf';
      crReport.Export(false);

please help me ...
Respond

RE: SQL Server
Avi Singh (Nov 22 2005 9:29AM)

correction to line 1

Application1.LogOnServer('pdsodbc.dll','TECHNO3','epics','foy','foy');
      
Respond

Crystal Report with Delphi 2005 32 bits
    Ederaldo Mirandola (Nov 14 2005 7:32PM)

Hello, the example explained in this site is valid for delphi 4 until 7. I use delphi 2005, what I need do to use Crytal Report 8.5 and Delphi 2005?
Thank you
Respond

RE: Crystal Report with Delphi 2005 32 bits
mojtaba musavi (Apr 29 2006 10:39PM)

its very usefull and we can improve it.
Respond

RE: RE: Crystal Report with Delphi 2005 32 bits
mojtaba musavi (Apr 29 2006 10:44PM)

i work with delphi 2005 please explain working crystal report with delphi 2005.
Respond

selection formula
    Alfredo Aguiar (Feb 27 2005 5:54PM)

CrystalReport1.Connect:="CONNECTIONSTRING";
CrystalReport1.ReportFileName:="LOCATION OF REPORT";
CrystalReport1.ReplaceSelectionFormula("SELECTIONFORMULA");
CrystalReport1.Action:=1;
Respond

RE: selection formula
ela (Jun 28 2005 6:28AM)

Using Crystal Reports in delphi exampel
Respond

RE: RE: selection formula
ela (Jun 28 2005 6:29AM)

Using Crystal Reports in delphi exampel
Respond

RE: RE: RE: selection formula
ela (Jun 28 2005 6:30AM)

Using Crystal Reports in delphi selection formula
Respond

RE: RE: selection formula
abdo (Sep 10 2005 11:20AM)

connect crystal report with delphi
Respond

RE: RE: RE: selection formula
lashkargir (Sep 16 2005 5:04AM)

how I can Using Crystal Reports in delphi exampel
Respond

RE: RE: RE: selection formula
lashkargir (Sep 16 2005 5:08AM)

how I can Using Crystal Reports delphi
Respond

RE: selection formula
samad (Dec 17 2005 10:51AM)

hello fdhgfhfghjnghj
Respond

Crystal Viewer
    Nonhlanhla Masilela (Nov 19 2004 11:20AM)

How do I pass parameters thru to my crystal report from my delphi front end?
Respond

RE: Crystal Viewer
Willliam Gama (Sep 21 2005 9:23PM)

You can use:
CrystalReport1.ParameterFields[1] := 'NombreParametro;'+ 'ValorParametro' + ';True';

Respond

Using Crystal Report in different ways
    Ahmad Fajar (May 8 2001 6:32AM)

You are using complicated way, may be here is an easy way, because I use this in my project.
1. From component : import ActiveX control and choose Crystal Report Control.
2. Add this new component to your form.
3. in your code you will have something like this : CrystalReport1: TCrystalReport;
4. Then add this code to your project :
procedure TForm1.FormCreate(Sender: TObject);
begin
   crystalreport1.ReportFileName := 'c:\report1.rpt';
   crystalreport1.Connect := 'Provider=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\Accounting.mdb;UID;PWD=;';
   crystalreport1.Action := 1;
// if you are using Microsoft Jet OLEDB you can change to this :
// crystalReport1.connect := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Accounting.mdb;Persist Security Info=False'
end;


Respond

RE: Using Crystal Report in different ways
Jeff Guidotti (May 9 2001 12:05AM)

I did play with that a bit, but wasn't able to get it to work well in my situation. I have designed a custom report writer in my software to allow creating of simple reports which I attach to at runtime using active data. I give my users the option of resizing and repositions columns, group heights, and other visual aspects. I will take another look at the Active X control since it seems easier to implement, but do you know off hand if I have the same access as through the automation?
Respond

RE: RE: Using Crystal Report in different ways
Ahmad Fajar (May 9 2001 10:41PM)

May you've forgot to make the database and the report. If you have design the report with Crystal Report 7.0 or higher and you have the database to connect to, I'am sure you will be able to view modify database at runtime and view it in CR windows or other child windows.
May be I could give you a sample project, I'll email it to you and you may publish it in this forum or the like if you like to publish it.
Your best regards,
Ahmad Fajar
Respond

RE: RE: Using Crystal Report in different ways
gachugu isaac (May 13 2002 8:44AM)

Hey, Iam sure you can be help pal.... I want to have dynamic reports as I think you have made it. ie. my clients can resize and reposition the columns and if possible add more features. How do you do it (Delphi 5). Also tell me more no the dynamic data exchange.
gachugu@yahoo.com . Thanks in advance.
Respond

RE: RE: Using Crystal Report in different ways
mohamad hmb (Jan 24 2007 1:01PM)

hi
I need to set ConnectionString in runtime.
my problem is here:
{*************************}
  CrystalRpt := CrystalApp.OpenReport('E:\Mine\Crystal Reports\ApplicationTest\MyReport1.rpt', crOpenReportByTempCopy);
  CrystalRpt.DiscardSavedData;
  with TADOConnection.Create(nil) do
  try
    ConnectionString := 'File Name=Data.UDL';
    Connected := True;
    CrystalRpt.Database.Tables[1].ConnectBufferString := ConnectionString;
  finally
    Free
  end;
  CrystalRpt.ParameterFields.GetItemByName('@p_nobat', '').AddCurrentValue('4');
  CrystalRpt.ParameterFields.GetItemByName('@p_xsch', '').AddCurrentValue('1000');
  CrystalRpt.ParameterFields.GetItemByName('@p_xgrouptest', '').AddCurrentValue(' ');
  CrystalView.ReportSource := CrystalRpt;
  CrystalView.ViewReport;
{***********************}
an error accored !
Respond

Crystal Reports comes with a VCL wrapper too
    Luigi Sandon (May 7 2001 1:40AM)

You can control and preview a report using the VCL wrapper which comes with Crystal Reports (or you can download it from Seagate's site). It does not require automation (it calls the CR APIs directly), threfore should be a little faster, and let you control and preview the report at design time too.
Respond

RE: Crystal Reports comes with a VCL wrapper too
Jeff Guidotti (May 8 2001 11:54PM)

That is true, but the VCL component is much more difficult to work with, and does not simply allow you to configure things in a report at run-time, like changing column sizes or positions. I worked with the VCL, but it did not meet my needs, and that is why I switched up to the automation. Also, the preview component is much more functional, and simplier to use.
Respond

OLEDB
    jose (Apr 30 2001 7:23AM)

i do this under sqlserver and crystal reports 8.0 and doesn`t run. My code is:
CrystalApp.LogOnServer('pdsoledb.dll','myservername','database','id','pwd_id') and an error ocurs at this line, 'Server it's no open'. what happens!!!
please can you help me, i'm on delphi 5

thanks a lot
Respond

RE: OLEDB
Jeff Guidotti (May 4 2001 4:51PM)

Sorry, but I do not use the OLE DB dll and I'm not sure if that's what might be causing the problem or not. I wish I could offer more help, but you can probably email Crystal Decisions on it for a more helpful answer.
Respond

RE: OLEDB
Fernando Jimenez (Jan 18 2002 1:02AM)

I hope this can help you

procedure TfmSales.PrintLogExecute(Sender: TObject);
var
i : Integer;
   RPTLocation,ServerName : String; //holds report path location string

   blank,prom,CurrentV,ValueT : olevariant;  //some of our calls use olevariants to pass strings
                        //blank is for null
begin RPTLocation := 'Sales\Reports\SalesLog.rpt';
        CrReport :=  application1.OpenReport(RPTLocation,1);
        ServerName := CrReport.Database.Tables.Get_Item(1).LogOnServerName ;
        CrReport.application.LogOnServer('pdsodbc.dll',ServerName,'Sales','sa','production');
        crReport.ParameterFields.Item[1].AddCurrentValue(CurrentID);
        prom := false;
        CrReport.SavePreviewPicture := True;
        CrReport.PrintOut(prom,blank,blank,blank,blank);
end;

but is easier if you use the Visual Component TCrystalReport.

Respond

IB
    Peter Morris (Apr 24 2001 6:22AM)

Can Crystal report directly from an Interbase server without me having to use ODBC ?

Respond

RE: IB
Jeff Guidotti (Apr 24 2001 8:33AM)

Crystal has a number of different connectivity options besides the ODBC. It supports ADO, RDO, DAO, and a host of others. I personally do not have much experience with Interbase so I cannot answer that question. You may want to try their web site at http://www.crystaldecisions.com/products/crystalreports/
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
I. Siticov
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)