Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi And Crystal reports- I do I overide a paramater? 1

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
So here is the problem,

I have a crystal report 8.5 file which I use with delphi 6 application that i am building.

I have two buttons on a form "Report" and "Query". This is what i would like to do...and i cant.

When i click the report button I wanna display my crystal file say "x.rpt" with every record in it.

And when i click "Query" I wanna display the file queried by date which the user chooses on the delphi form using calendar compnent in delphi.

Now here is the problem, Suppose the report has a field called "Call Date" which had all records on 06/20/03.
What I do is, include a Parameter Field called "CallDate" which takes the date from the calendar component and only displays those record that match.

So if the user choses "06/20/03" from the calendar component on the form and hits "Query" it will display all records on that date.

But when the user hits "Report" I get and empty report! I want crystal to show every record, but instead it takes the default date in the "CallDate" parameter which might not occur in the report and displays an empty report.

How do I override the "CallDate" Parameter. How do I write a query to do that. I tried doing any value on date in the Select Expert which works fine except for that fact that delphi code throws an error.

If delphi code looks like this

with Report do
begin
ReportName := ExtractFilePath(Application.ExeName) + 'reports\X.RPT';
{Pass the report name and path}

ParamFields.Retrieve;
{Retrieve the parameters in the report}

ParamFields[0].AsDate := dtpBeginDate.Date;
{Pass the date selected in the DateTimePicker(calendar component)}

Output := toWindow;
{Tell it where to output}

WindowState := wsNormal;
{Specify how to display the report}

WindowZoom.Preview := pwPageWidth;
{Specify the report view size}

Execute;
{Print the report}

end;

Then what should i put on the RHS when i do "anyvalue" in the SELECT EXPERT ?

ParamFields[0].??? := ???????????
 
I'd recommend making a slight modification to the underlying Crystal Report (if you can !?) initially for you to achieve your aim quickly and easily (if practical)
Rather than have the parameter 'CallDate' already set in the report's Selection, just have the parameter there to use.
According to which button your user adds you then set the 'RecordSelectionFormula' appropriately, either including the use of this 'CallDate' parameter or not accordingly (building the selection on the fly and passing it to the report).
I hope that this helps.
Steve
 
hi

It's a while back that I used Crystal. I had somethng like this but I can't remember if these are crystal library calls or InfoPower function calls(I think I used).

procedure TFrm_ReportAncestor.SetParamField(sValue : string; idx : integer);
var fieldInfo: TCDCParameterFieldInfo;
begin
fieldInfo := CDRep.GetNthCDCParameterField(idx);
if fieldInfo <> nil then
begin
fieldInfo.CurrentValue.AsString := sValue;
fieldInfo.SetField;
fieldInfo.Free;
end
else
raise exception.Create('Report title error');
end;

procedure TFrm_ReportAncestor.SetParamFieldInt(iValue : Integer; idx : integer);
var fieldInfo: TCDCParameterFieldInfo;
begin
fieldInfo := CDRep.GetNthCDCParameterField(idx);
if fieldInfo <> nil then
begin
fieldInfo.CurrentValue.AsInteger := iValue;
fieldInfo.SetField;
fieldInfo.Free;
end
else
raise exception.Create('Report title error');
end;

The fastest and most solid way a found was the following (probably not the most elegant, but I found it very reliable).

- I found crystal much faster when it does a straight read from a table, so
1. I created a report table which contained the data I wanted shown in the report. This table was populated by running a query in delphi and the data would then sit in there until a the query was redone. I added a reportedDate field to the table aswell and showed this on the crystalreport.
2. Had a static, simple stored proc containing, eg, 'select * from MyReportTable'.
3. Use the storedProc inside the report to populate it. NB, you don't really need the storedproc, you could do a direct 'select * from MyReportTable' in the crystal report. I had it like this at the time because I found it easier just to edit the stored proc rather than keep going in to report designer.

This method is also good for testing your report too, aswell as showing the previously reported data. You can extend this by adding a userid col in the report table to view different report data for different users.

This doesn't directly answer your question but hopefully gives you some ideas of different ways to populate your reports.

lou

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top