Using Report Designer Component with Visual C++ 6.0

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...
LVL 3
abdkhlaifAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
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
abdkhlaifAuthor Commented:
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
mlmccCommented:
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
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

abdkhlaifAuthor Commented:

I already did, take a look at my first post.
0
mlmccCommented:
I see where you are using the GET which is probably readonly.  Did you try it without the GET

mlmcc
0
abdkhlaifAuthor Commented:
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
mlmccCommented:
Try it like this

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

mlmcc
0
mlmccCommented:
Try it like this

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

mlmcc
0
mlmccCommented:
Or better

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

mlmcc
0
abdkhlaifAuthor Commented:

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

0
EwaldLCommented:
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
abdkhlaifAuthor Commented:
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
abdkhlaifAuthor Commented:

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
abdkhlaifAuthor Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
YensidModCommented:
Question is PAQed and 75 points refunded.

YensidMod
Experts Exchange Moderator
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.