Solved

Using Report Designer Component with Visual C++ 6.0

Posted on 2003-11-16
15
728 Views
Last Modified: 2007-12-19
Hi..

[Using: Visual C++ 6.0, MFC Dialog-Based Application, Report Designer Component, Crystal Reports 8.5]

I'm trying to develop a dialog based application that opens a report and passes the required parameters then refresh and export it to a destination folder. The application uses Report Designer Component to pass parameters to a report programatically. I referred to document "scr_rdc_cpp.pdf" from Crystal Reports Support, and came up with the following code:

// CTestApp :
IApplicationPtr gApplication;
IReportPtr gReport;

// CTestDlg :
extern CReportSchedulerApp theApp;

void CTestDlg::OnOpenReport()
{
   CFileDialog fd(TRUE, "*.rpt", NULL, OFN_EXPLORER, "Crystal Reports|*.rpt||");

   if(fd.DoModal() == IDOK)
   {
      _bstr_t bsFile = fd.GetPathName();

      theApp.gApplication.CreateInstance("CrystalDesignRuntime.Application");
      theApp.gReport = theApp.gApplication->OpenReport(bsFile);
   }
}

void CTestDlg::OnRefreshReport()
{
   UpdateData(TRUE);

   VARIANT varFrom, varTo; // the report requires two date parameters: from & to
   DATE dFrom, dTo;
   SYSTEMTIME systFrom, systTo;

   m_tFromDate.GetAsSystemTime(systFrom); // a date-time picker control
   m_tToDate.GetAsSystemTime(systTo); // a date-time picker control

   VariantInit(&varFrom);
   VariantInit(&varTo);

   SystemTimeToVariantTime(&systFrom, &dFrom);
   SystemTimeToVariantTime(&systTo, &dTo);

   varFrom.vt   = VT_DATE;
   varFrom.date = dFrom;

   varTo.vt   = VT_DATE;
   varTo.date = dTo;

   theApp.gReport->GetParameterFields()->GetItem(1)->AddCurrentValue(varFrom);
   theApp.gReport->GetParameterFields()->GetItem(2)->AddCurrentValue(varTo);
}

When I run the application, and reach the call to AddCurrentValue(), I get "Abnormal Program Termination".. I think the part that causes this problem is the last two lines in the code shown above. The very strange thing that drives me crazy is that if I replace the call to AddCurrentValue() with GetCurrentValue(), the application works fine !!! I got the impression that I can read data, put I can't change.. i.e. gReport is readonly??

I realy need to solve this problem because the thing is this application is actually a report scheduler that will be used to schedule Crystal Reports to refresh and export automatically..

PLEASE HELP...
0
Comment
Question by:abdkhlaif
15 Comments
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Instead of this line


   theApp.gReport->GetParameterFields()->GetItem(1)->AddCurrentValue

is there perhaps a

   theApp.gReport->SetParameterFields()->SetItem(1)->AddCurrentValue

I think by using the Get you are using a readonly field.

mlmcc
0
 
LVL 3

Author Comment

by:abdkhlaif
Comment Utility
Hi..

The GetParameterFields() retreives a pointer to IParameterFieldDefinitions object that points to all the report parameters. Its like an array of IParameterFieldDefinition objects (without 's'), which in turn has a set of methods and properties to access the value of the parameter. The value of the parameter is always of type VARIANT.

In fact, the reason why I'm using this method is because its mentioned in the only document provided by Crystal Reports Support that describes using RDC with Visual C++ 6.0

Here is the document:
http://support.crystaldecisions.com/communityCS/TechnicalPapers/scr_rdc_cpp.pdf.asp?recDnlReq=Record&dnlPath=scr_rdc_cpp.pdf

I think the main problem here is that there is no enough documentation regarding this subject..

I'm running out of ideas, so any more ideas are deeply appreciated.
Thanx in advance
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Use something like

VARIANT NumberParam;
VariantInit(&NumberParam);
NumberParam.vt = VT_I2;
NumberParam.iVal = 10;
app->pReport->ParameterFields->Item[2]->AddCurrentValue(NumberParam);

You can use your code to find the correct parameter.

mlmcc
0
 
LVL 3

Author Comment

by:abdkhlaif
Comment Utility

I already did, take a look at my first post.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
I see where you are using the GET which is probably readonly.  Did you try it without the GET

mlmcc
0
 
LVL 3

Author Comment

by:abdkhlaif
Comment Utility
Yes, I tried this:

theApp.gReport->ParameterFields->Item[1]->CurrentValue.date = dDate;

and I got this:

"error C2106: '=' : left operand must be l-value"

No Get's or even Set's, and still there is something wrong...


0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Try it like this

app->pReport->ParameterFields->Item[2]->AddCurrentValue(dDate);

mlmcc
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Try it like this

app->pReport->ParameterFields->Item[2]->AddCurrentValue(dDate);

mlmcc
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Or better

app->pReport->ParameterFields->Item[1]->AddCurrentValue(dDate);

mlmcc
0
 
LVL 3

Author Comment

by:abdkhlaif
Comment Utility

I already tried all the possible combinations, the same error.

0
 
LVL 13

Expert Comment

by:EwaldL
Comment Utility
i would guess the problem is rather related to the parameter type that is passed. here is a sample of a time parameter being passed to a cr 8.5 report using the rdc in c++. i would assume that by changing the paramter VAR_TIMEVALUEONLY you could also pass a date

http://support.crystaldecisions.com/library/kbase/articles/c2010722.asp
0
 
LVL 3

Author Comment

by:abdkhlaif
Comment Utility
Thanx for reply.

During debug, I verified that varFrom.date is valid and contains the correct date value.

I tried this method, but no change. The same annoying error.

0
 
LVL 3

Author Comment

by:abdkhlaif
Comment Utility

This document: http://support.crystaldecisions.com/communityCS/TechnicalPapers/scr_rdc_cpp.pdf.asp?recDnlReq=Record&dnlPath=scr_rdc_cpp.pdf

says that before using RDC in my project, I should open the project's main header file and add the following line:
#import "craxdrt.dll" no_namespace

Is there a different way instead of this? is it possible that using 'import' directive could cause runtime errors?
0
 
LVL 3

Accepted Solution

by:
abdkhlaif earned 0 total points
Comment Utility
Guys,

I figured out what was the source of the problem..

I was passing the date as {28-Nov-03 3:00:00 AM VT_DATE} but my report accepts only this: {28-Nov-03 12:00:00 AM VT_DATE} where the time is 12:00:00 AM, no more, no less (I don't know why)

Thanks for your replies.
0
 

Expert Comment

by:YensidMod
Comment Utility
Question is PAQed and 75 points refunded.

YensidMod
Experts Exchange Moderator
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now