Hi,
I was trying to run a crystal report in the .net sample application
given at:
http://support.crystaldecisions.com/...lesAndUpdates/
cppnet_win_subr eport_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::Ru n(new ViewForm());
at the end of the file with:
Application::Ru n(new ViewForm());
Application::Ru n(new ViewForm());
Application::Ru n(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 <CrystalDecisio ns.Shared.dll>
#using <CrystalDecisio ns.Windows.Form s.dll>
#using <CrystalDecisio ns.CrystalRepor ts.Engine.dll>
using namespace System;
using namespace System::Windows ::Forms;
using namespace CrystalDecision s::Shared;
using namespace CrystalDecision s::CrystalRepor ts::Engine;
using namespace CrystalDecision s::Windows::For ms;
// 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.
CrystalDecision s::Windows::For ms::CrystalRepo rtViewer* crViewer;
ReportDocument* crReportDocumen t;
ParameterFieldD efinitions* crParameterFiel dDefinitions;
ParameterFieldD efinition* crParameterFiel dDefinition;
ParameterValues * crParameterValu es;
ParameterDiscre teValue* crParameterDisc reteValue;
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
CrystalDecision s::Windows::For ms::CrystalRepo rtViewer();
this->crViewer->ActiveViewInde x = -1;
this->crViewer->Dock = System::Windows ::Forms::DockSt yle::Fill;
this->crViewer->Name = "crystalReportV iewer1";
this->crViewer->TabIndex = 0;
this->Controls->Add (this->crViewer);
//This attaches the form load event to the function.
this->Load += new System::EventHa ndler (this, ViewForm_Load);
}
void ViewForm_Load(S ystem::Object* sender, System::EventAr gs* e)
{
String* crParamVal;
//Instantiate the report and load the report.
crReportDocumen t = new ReportDocument ();
crReportDocumen t->Load
("C:\\Crystal\\ crnet\\cppnet_w in_paramengine\ \CRParams.rpt") ;
//Get the collection of parameters from the report
crParameterFiel dDefinitions =
crReportDocumen t->DataDefiniti on->ParameterField s;
//Access the specified parameter from the collection
crParameterFiel dDefinition =
crParameterFiel dDefinitions->Item ["Country"];
//Get the current values from the parameter field. At
this point
//there are zero values set.
crParameterValu es = crParameterFiel dDefinition->CurrentValue s;
//Set the current values for the parameter field
crParamVal = "Canada";
crParameterDisc reteValue = new ParameterDiscre teValue();
crParameterDisc reteValue->Value = crParamVal; //1st
current value
//Add the first current value for the parameter field
crParameterValu es->Add(crParamete rDiscreteValue) ;
//Since this parameter allows multiple values, the
discrete value
//object needs to be reset. Destroy the previous instance
and create
//a new instance.
crParameterDisc reteValue = 0;
crParameterDisc reteValue = new ParameterDiscre teValue();
//Add the second current value for the parameter field
crParamVal = "USA";
crParameterDisc reteValue->Value = crParamVal; //2nd current value
crParameterValu es->Add(crParamete rDiscreteValue) ;
//All current parameter values must be applied for the
parameter field.
crParameterFiel dDefinition->ApplyCurrentVa lues(crParamete rValues);
//Set the viewer to the report object to be previewed.
crViewer->ReportSource = crReportDocumen t;
}
};
// This is the entry point for this application
#ifdef _UNICODE
int wmain(void)
#else
int main(void)
#endif
{
Application::Ru n(new ViewForm());
return 0;
};