Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using Report Designer Component with Visual C++ 6.0

Posted on 2003-11-16
15
Medium Priority
?
776 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 9758779
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
ID: 9759841
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 101

Expert Comment

by:mlmcc
ID: 9761388
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
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
LVL 3

Author Comment

by:abdkhlaif
ID: 9767390

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

Expert Comment

by:mlmcc
ID: 9768812
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
ID: 9770603
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 101

Expert Comment

by:mlmcc
ID: 9775527
Try it like this

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

mlmcc
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 9775528
Try it like this

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

mlmcc
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 9775559
Or better

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

mlmcc
0
 
LVL 3

Author Comment

by:abdkhlaif
ID: 9777053

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

0
 
LVL 13

Expert Comment

by:EwaldL
ID: 9780717
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
ID: 9782824
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
ID: 9782904

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
ID: 9842621
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
ID: 9842951
Question is PAQed and 75 points refunded.

YensidMod
Experts Exchange Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

661 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