Monik22
asked on
Creating crystal reports
I USE DELHPI 6, AND CRYSTAL REPORTS 8.5, AND THE DATABASE IS MS SQL SERVER.
THIS IS WHAT I HAVE ON MY CODE:
unit ReportUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB, dbtables, CheckLst, Buttons, CRVIEWERLib_TLB, CRAXDRT_TLB,
OleCtrls, OleServer;
type
TReportForm = class(TForm)
ReportViewer: TCRViewer;
CrystalApplication: TApplicationCrystal;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
CrReport : Ireport; //the new Report
CrField : IFieldObject; //use to format fields
CrDbField : IDatabaseFieldDefinition; //use a database field
end;
var
ReportForm: TReportForm;
implementation
uses
MainUnit;
{$R *.dfm}
procedure TReportForm.FormCreate(Sen der: TObject);
var
i : Integer;
blank : olevariant;
begin
//Create report
CrReport := CrystalApplication.NewRepo rt;
//Add a table to a the report
CrReport.Database.Tables.A dd('Geoffr eySQL',bla nk,blank,b lank,blank ,blank,bla nk,blank,b lank,blank );
for i := 0 to MainForm.ColumnsCheckListB ox.Items.C ount - 1 do
begin
if MainForm.ColumnsCheckListB ox.Checked [i] then
begin
//Add a Couple of fields to the detail section
CRField := CrReport.Sections.Item ['D'].AddFieldObject(MainF orm.Column sCheckList Box.Items. Strings[i] ,600,0);
end;
end;
//set the report to the CrViewer object and view the report
ReportViewer.ReportSource := CrReport;
ReportViewer.ViewReport;
end;
end.
MY CODE IS FAILING AT THE "//Add a table to a the report" PART, CAN SOMEONE HELP ME WITH THIS. THIS IS MY FIRST TIME USING DELPHI.
THANKS,
MONICA.
THIS IS WHAT I HAVE ON MY CODE:
unit ReportUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB, dbtables, CheckLst, Buttons, CRVIEWERLib_TLB, CRAXDRT_TLB,
OleCtrls, OleServer;
type
TReportForm = class(TForm)
ReportViewer: TCRViewer;
CrystalApplication: TApplicationCrystal;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
CrReport : Ireport; //the new Report
CrField : IFieldObject; //use to format fields
CrDbField : IDatabaseFieldDefinition; //use a database field
end;
var
ReportForm: TReportForm;
implementation
uses
MainUnit;
{$R *.dfm}
procedure TReportForm.FormCreate(Sen
var
i : Integer;
blank : olevariant;
begin
//Create report
CrReport := CrystalApplication.NewRepo
//Add a table to a the report
CrReport.Database.Tables.A
for i := 0 to MainForm.ColumnsCheckListB
begin
if MainForm.ColumnsCheckListB
begin
//Add a Couple of fields to the detail section
CRField := CrReport.Sections.Item ['D'].AddFieldObject(MainF
end;
end;
//set the report to the CrViewer object and view the report
ReportViewer.ReportSource := CrReport;
ReportViewer.ViewReport;
end;
end.
MY CODE IS FAILING AT THE "//Add a table to a the report" PART, CAN SOMEONE HELP ME WITH THIS. THIS IS MY FIRST TIME USING DELPHI.
THANKS,
MONICA.
ASKER
I don't know what does blank equal.
This is what the original code looked like:
{Created by Trevor Dubinsky on Tuesday February 22nd 1999
This is a simple application demonstrating how to create a report
on the fly using Delphi.
First step is to choose import type library from the Component menu
Import "Crystal Reports 8 Active x Designer Run Time Library. It will
complain that TReport and TDatabase are already registered. Just rename
them to TCrReport and TCrDatabase
You will also want to import the CRystal reports viewer control.
Once these are installed the following code should work.
Note that there is a TApplication object on the main form. This object
is a craxdrt.application object and will overide the Delphi application object'
I don't know the work around to this yet.
I will be using a sample table called customer.db which is in this project
directory, in code I look for it in the root of C Drive.
I do want to reiterate that this is a VERY SIMPLE example showing how to create
a detailed report. I will update this to have a white paper with better
description and information; as time permits}
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtrls, CRVIEWERLib_TLB, CRAXDRT_TLB, OleServer;
type
TForm1 = class(TForm)
CRViewer1: TCRViewer;
Application1: TApplication;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
CrReport : Ireport; //the new Report
CrField : IFieldObject; //use to format fields
crDbField : IDatabaseFieldDefinition; //use a database field
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
DbLocation : String; //holds database location string
location,
blank : olevariant; //some of our calls use olevariants to pass strings
//blank is for null
begin
//First create a new report
CrReport := application1.NewReport;
//Add a table to a the report
Location := 'c:\customer.db';
CrReport.Database.Tables.A dd (location,blank,blank,blan k,blank,bl ank,blank, blank,blan k,blank);
//Add a Couple of fields to the detail section
CRField := CrReport.Sections.Item ['D'].AddFieldObject('{Cus tomer.Cust omer Name}',600,0);
CRField := CrReport.Sections.Item ['D'].AddFieldObject('{Cus tomer.last years sales}',4500,0);
//Lets add a group to the report (by region, in ascending order)
CRDbField := CrReport.Database.Tables.I tem [1].Fields[12];
crreport.AddGroup (0,CrDbField,crGCAnyValue, CrAscendin gOrder);
//Add the region field to the Group header section and format it
CRField := CrReport.Sections.Item ['GH1'].AddFieldObject('{C ustomer.Re gion}',600 ,0);
CRField.TextColor := clblue;
//set the report to the CrViewer object and view the report
CRViewer1.ReportSource := CrReport;
CRViewer1.ViewReport;
end;
end.
This is what the original code looked like:
{Created by Trevor Dubinsky on Tuesday February 22nd 1999
This is a simple application demonstrating how to create a report
on the fly using Delphi.
First step is to choose import type library from the Component menu
Import "Crystal Reports 8 Active x Designer Run Time Library. It will
complain that TReport and TDatabase are already registered. Just rename
them to TCrReport and TCrDatabase
You will also want to import the CRystal reports viewer control.
Once these are installed the following code should work.
Note that there is a TApplication object on the main form. This object
is a craxdrt.application object and will overide the Delphi application object'
I don't know the work around to this yet.
I will be using a sample table called customer.db which is in this project
directory, in code I look for it in the root of C Drive.
I do want to reiterate that this is a VERY SIMPLE example showing how to create
a detailed report. I will update this to have a white paper with better
description and information; as time permits}
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtrls, CRVIEWERLib_TLB, CRAXDRT_TLB, OleServer;
type
TForm1 = class(TForm)
CRViewer1: TCRViewer;
Application1: TApplication;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
CrReport : Ireport; //the new Report
CrField : IFieldObject; //use to format fields
crDbField : IDatabaseFieldDefinition; //use a database field
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
DbLocation : String; //holds database location string
location,
blank : olevariant; //some of our calls use olevariants to pass strings
//blank is for null
begin
//First create a new report
CrReport := application1.NewReport;
//Add a table to a the report
Location := 'c:\customer.db';
CrReport.Database.Tables.A
//Add a Couple of fields to the detail section
CRField := CrReport.Sections.Item ['D'].AddFieldObject('{Cus
CRField := CrReport.Sections.Item ['D'].AddFieldObject('{Cus
//Lets add a group to the report (by region, in ascending order)
CRDbField := CrReport.Database.Tables.I
crreport.AddGroup (0,CrDbField,crGCAnyValue,
//Add the region field to the Group header section and format it
CRField := CrReport.Sections.Item ['GH1'].AddFieldObject('{C
CRField.TextColor := clblue;
//set the report to the CrViewer object and view the report
CRViewer1.ReportSource := CrReport;
CRViewer1.ViewReport;
end;
end.
Dear expert(s),
A request has been made to close this Q in CS:
https://www.experts-exchange.com/questions/20455028/Deleting-questions.html
Without a response in 72 hrs, a moderator will finalize this question by:
- Saving this Q as a PAQ and refunding the points to the questionner
When you agree or disagree, please add a comment here.
Thank you.
modulo
Community Support Moderator
Experts Exchange
A request has been made to close this Q in CS:
https://www.experts-exchange.com/questions/20455028/Deleting-questions.html
Without a response in 72 hrs, a moderator will finalize this question by:
- Saving this Q as a PAQ and refunding the points to the questionner
When you agree or disagree, please add a comment here.
Thank you.
modulo
Community Support Moderator
Experts Exchange
Sorr ythis took so long but I was gone for about 10 days and have been slow getting through the emails.
Take a look at
http://support.crystaldecisions.com/communityCS/TechnicalPapers/apps_delphi.pdf
mlmcc
Take a look at
http://support.crystaldecisions.com/communityCS/TechnicalPapers/apps_delphi.pdf
mlmcc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can you close this Q and refund points.
Thanks
Thanks
Hi Monik22,
Giving me a "C" grade doesn't help.
I denied the request as you didn't comment on the link mlmcc provided you with.
As I'm not allowed to have expert points as moderator, I've transferred them to a "Points for mlmcc" question:
https://www.experts-exchange.com/questions/20467175/Points-for-mlmcc.html
When you disagree with my handling, feel free to mail the site admin:
computer101@experts-exchan ge.com
modulo
Community Support Moderator
Experts Exchange
Giving me a "C" grade doesn't help.
I denied the request as you didn't comment on the link mlmcc provided you with.
As I'm not allowed to have expert points as moderator, I've transferred them to a "Points for mlmcc" question:
https://www.experts-exchange.com/questions/20467175/Points-for-mlmcc.html
When you disagree with my handling, feel free to mail the site admin:
computer101@experts-exchan
modulo
Community Support Moderator
Experts Exchange
Take a look at
http://support.crystaldecisions.com/library/kbase/articles/c2009096.asp
http://support.crystaldecisions.com/library/kbase/articles/c2008699.asp
mlmcc