Discussion:
Crstal Report 9.0 ...........
(too old to reply)
TopGunVC
2006-07-24 08:14:01 UTC
Permalink
Hi All,
I calling Crstal Report through my application.
It is working fine when I am calling at first time, but when I am calling it
2nd time It is getiing crashed in Dialog DoModal() fucntion.

Can U help me to resolve this

///////////////////////////Pice of code//////////////////////////
//where i am calling this report viewer dialog

CRptViewer* m_RptViewer = new CRptViewer(); //This is my Report viewer
dialog box

m_bsReportFileName="SynEmpTrackTool_DetailRpt.rpt";

m_RptViewer->m_bsWhere=csFilter;

m_RptViewer->DoModal();

////////////////////////////////////////////////////////////////////////////////
//This is my Init dialog cod
/////////////////////////////////////////////////////////////////////////////////////////////
BOOL CRptViewer::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
//get the dialog rectangle
this->GetWindowRect(&m_RInitDlg);

m_CtrlRptViewer9.GetWindowRect(&m_CtrlInit);


//m_CtrlRptViewer9.ClientToScreen(&m_RInitDlg);

//CoInitialize(NULL) ;


HRESULT hr =
m_Application.CreateInstance("CrystalDesignRuntime.Application");

//Error handling
if(hr==S_FALSE)
{
AfxMessageBox("Unable to create RDC instance.");
m_Application.Release();
return FALSE;
}

// SysFreeString(m_DLLName);
m_DLLName = "crdb_odbc.dll";

//Create Report Object

// SysFreeString(m_bsReportFileName);
m_bsReportFileName="SynEmpTrackTool_DetailRpt.rpt";

m_Report = m_Application->OpenReport(m_bsReportFileName);

//m_Report =
m_Application->OpenReport(SysAllocString(L,"SynEmpTrackTool_DetailRpt.rpt"));

if(m_Report==NULL)
{
AfxMessageBox("Unable to create Report Object");
return FALSE;
}

//Set connection to Database

m_Report->Database->Tables->Item[1]->ConnectionProperties->DeleteAll();

HRESULT hr1 =
m_Report->Database->Tables->Item[1]->ConnectionProperties->Add("DSN", "test");
HRESULT hr2 =
m_Report->Database->Tables->Item[1]->ConnectionProperties->Add("User ID",
"sa");
HRESULT hr3 =
m_Report->Database->Tables->Item[1]->ConnectionProperties->Add("Password",
"");
HRESULT hr4 =
m_Report->Database->Tables->Item[1]->ConnectionProperties->Add("Database",
"EmpTrack");
HRESULT hr5 =
m_Report->Database->Tables->Item[1]->ConnectionProperties->Add("DllName",
m_DLLName);

if(hr1==S_FALSE|| hr2==S_FALSE || hr3==S_FALSE|| hr4==S_FALSE ||
hr5==S_FALSE)
{
AfxMessageBox("Unable to create Connection properties on this Database
with the given login information.");
m_Report->Database->Tables->Item[1]->ConnectionProperties->DeleteAll();
m_Report->Release();
return FALSE;
}

for(int i=1; i<= m_Report->Database->Tables->Count;i++)
{
m_Report->Database->Tables->Item[i]->Location = m_Database + ".dbo."+
m_Report->Database->Tables->Item[i]->Name;
}

//To verify if database connection has been established correctly.
//HRESULT hr5 = m_Report->Database->Verify();

m_Report->DiscardSavedData();

/* Loop through each section on the report then look through each object in
the section. If the object is a subreport, then apply logon info
on each table of that sub report*/

CComVariant Var , Var1 ;
long SecObjCntr= 0;


m_Report->PutRecordSelectionFormula(m_bsWhere);

m_CtrlRptViewer9.SetReportSource(m_Report);

// View the report in the Crystal Reports Viewer control.

m_CtrlRptViewer9.ViewReport();

//To display the dialog frame in its maximized form.
ShowWindow(SW_SHOWMAXIMIZED);
//To fit the ActiveEx Control into the dialog frame.
CRect pRect(0,0,0,0);

GetWindowRect(&pRect);

CRect pRectRpt(0,0,0,0);
m_CtrlRptViewer9.GetWindowRect(pRectRpt);

m_CtrlRptViewer9.SetWindowPos(this,0,0,pRect.Width(),pRectRpt.Height(),SWP_SHOWWINDOW);

//CoUninitialize() ;

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE

/////////////////////////////////////////////////////////////////////////////////////////////
Frank Hickman [MVP]
2006-08-11 07:56:12 UTC
Permalink
Post by TopGunVC
Hi All,
I calling Crstal Report through my application.
It is working fine when I am calling at first time, but when I am calling it
2nd time It is getiing crashed in Dialog DoModal() fucntion.
Can U help me to resolve this
///////////////////////////Pice of code//////////////////////////
//where i am calling this report viewer dialog
CRptViewer* m_RptViewer = new CRptViewer(); //This is my Report viewer
dialog box
m_bsReportFileName="SynEmpTrackTool_DetailRpt.rpt";
m_RptViewer->m_bsWhere=csFilter;
m_RptViewer->DoModal();
<snip>

You may want to use m_RptViewer->ShowWindow instead of DoModal. It appears
to me that your dialog is modeless so you should not use DoModal. If you
want to use DoModal, try declaring it like this...

CRptViewer m_RptViewer();
--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the ***@m_ with @ to reply.
Loading...