Hi,
I was trying to run a crystal report in the .net sample application
given at:
http://support.crystaldecisions.com/...lesAndUpdates/
cppnet_win_subreport_basic.exe.asp
(I've reproduced the relevant file below.)
However, I want to view the report three times in a row.
I tried replacing:
Application::Run(new ViewForm());
at the end of the file with:
Application::Run(new ViewForm());
Application::Run(new ViewForm());
Application::Run(new ViewForm());
However, the second time Run() is called, the viewer comes up, then
disappears immediately. It works fine the third time. I checked, and
it works fine every odd time, and fails every even time.
Anyone have any idea what I'm doing wrong?
Thanks muchly,
Dean
------------------------------------------------
//********************************************
//Created: March 27, 2002
//Author ID: TDU
//Purpose: This C++ .NET sample Windows application demonstrates
how to
// pass multiple values to a single discrete parameter
field
// using the engine object model.
//********************************************
//Both of these CR assemblies are required to be able to
//access, load, and set database logon.
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <CrystalDecisions.Shared.dll>
#using <CrystalDecisions.Windows.Forms.dll>
#using <CrystalDecisions.CrystalReports.Engine.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace CrystalDecisions::Shared;
using namespace CrystalDecisions::CrystalReports::Engine;
using namespace CrystalDecisions::Windows::Forms;
// This is the main form that will hold the viewer control.
__gc class ViewForm : public System::Windows::Forms::Form
{
private:
//Declare the Viewer Control, Report Document, and other
//objects needed to set the Parameter values.
CrystalDecisions::Windows::Forms::CrystalReportVie wer* crViewer;
ReportDocument* crReportDocument;
ParameterFieldDefinitions* crParameterFieldDefinitions;
ParameterFieldDefinition* crParameterFieldDefinition;
ParameterValues* crParameterValues;
ParameterDiscreteValue* crParameterDiscreteValue;
public:
//Public constructor
ViewForm()
{
InitForm() ;
}
//destructor
~ViewForm()
{
this->Dispose() ;
}
void InitForm()
//This function initializes the form and adds the viewer to the
form.
{
// Instantiate the viewer control and add it to the form
this->crViewer = new
CrystalDecisions::Windows::Forms::CrystalReportVie wer();
this->crViewer->ActiveViewIndex = -1;
this->crViewer->Dock = System::Windows::Forms::DockStyle::Fill;
this->crViewer->Name = "crystalReportViewer1";
this->crViewer->TabIndex = 0;
this->Controls->Add (this->crViewer);
//This attaches the form load event to the function.
this->Load += new System::EventHandler (this, ViewForm_Load);
}
void ViewForm_Load(System::Object* sender, System::EventArgs* e)
{
String* crParamVal;
//Instantiate the report and load the report.
crReportDocument = new ReportDocument ();
crReportDocument->Load
("C:\\Crystal\\crnet\\cppnet_win_paramengine\\CRPa rams.rpt");
//Get the collection of parameters from the report
crParameterFieldDefinitions =
crReportDocument->DataDefinition->ParameterFields;
//Access the specified parameter from the collection
crParameterFieldDefinition =
crParameterFieldDefinitions->Item ["Country"];
//Get the current values from the parameter field. At
this point
//there are zero values set.
crParameterValues = crParameterFieldDefinition->CurrentValues;
//Set the current values for the parameter field
crParamVal = "Canada";
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue->Value = crParamVal; //1st
current value
//Add the first current value for the parameter field
crParameterValues->Add(crParameterDiscreteValue);
//Since this parameter allows multiple values, the
discrete value
//object needs to be reset. Destroy the previous instance
and create
//a new instance.
crParameterDiscreteValue = 0;
crParameterDiscreteValue = new ParameterDiscreteValue();
//Add the second current value for the parameter field
crParamVal = "USA";
crParameterDiscreteValue->Value = crParamVal; //2nd current value
crParameterValues->Add(crParameterDiscreteValue);
//All current parameter values must be applied for the
parameter field.
crParameterFieldDefinition->ApplyCurrentValues(crParameterValues);
//Set the viewer to the report object to be previewed.
crViewer->ReportSource = crReportDocument;
}
};
// This is the entry point for this application
#ifdef _UNICODE
int wmain(void)
#else
int main(void)
#endif
{
Application::Run(new ViewForm());
return 0;
};