Hi.
I have a problems with closing reports during run-time using Crystal Report Designer Component (RDC) from
Crystal Repotrs 8.5 with Visual C++ 6.0. I have the following member variables defined in my appilication CWinApp-derived
class:
IApplicationPtr m_pApplication;
IReportPtr m_pReport;
IFieldObjectPtr m_pobjDetail[3]; // fields pointers array for three objects
ITextObjectPtr m_pobjHeader[3]; // text pointers array for three objects
ITextObjectPtr m_pobjFooter; // fields pointer for report footer
CCrystalReportViewer4* m_pCryst;
CAdodc m_ctlADODC; // Microsoft ADO Data Control
At application startup I'm initializing m_pApplication and creating CCrystalReportViewer4 object:
...
m_pApplication.CreateInstance("CrystalRuntime.Application"
m_pCryst=new CCrystalReportViewer4;
...
After that I'm creating ADO Data Control window. When user selects a new database, I'm setting new
ADO record source and creating new report during run-time at the following manner:
ISectionPtr pSection,pHeaderSection,pFooterSection;
ISectionPtr pGroupSection;
...
// get reference to my ADO recordset
CAdodc& refADO=m_ctlADODC;
C_Recordset& rc=refADO.GetRecordset();
// creating a new report (***)
m_pReport=m_pApplication->NewReport();
// add database to a report (THE REASON OF MY HEADACHE)
m_pReport->Database->Tables->Add("",vTemp,_variant_t((IDispatch *)rc.m_lpDispatch,true),vTemp,"p2smon.dll"
// get the Detail section using "D" and Header section using "PH" as the index
pSection=m_pReport->Sections->GetItem("D"
pHeaderSection=m_pReport->Sections->GetItem("PH"
pFooterSection=m_pReport->Sections->GetItem("PF"
// add data to the report's Header section
m_pobjHeader[0]=pHeaderSection->AddTextObject("Field1",400,0);
m_pobjHeader[1]=pHeaderSection->AddTextObject("Field2",1100,0);
m_pobjHeader[2]=pHeaderSection->AddTextObject("Field3",2900,0);
// add data to the report's Detail section
m_pobjDetail[0]=pSection->AddFieldObject("{ado.Field1}",400,0);
m_pobjDetail[1]=pSection->AddFieldObject("{ado.Field2}",1100,0);
m_pobjDetail[2]=pSection->AddFieldObject("{ado.Field3}",2900,0);
// add data to the report's Footer section
_bstr_t bstrMessage("My report footer"
m_pobjFooter=pFooterSection->AddTextObject(bstrMessage,0,0);
::SysFreeString(bstrMessage);
// pass the report to the viewer and preview the report
m_pCryst->SetReportSource(NULL);
m_pCryst->SetReportSource(m_pReport);
m_pCryst->Zoom(100);
m_pCryst->ViewReport();
...
Above code works fine and I can see a valid report.
When user closes current database, I'm trying to close ADO recordset and report:
C_Recordset& rc=m_ctlADODC.GetRecordset();
if (rc.m_lpDispatch!=NULL) rc.Close(); // close recordset if it wasn't closed previously
// destroy footer since it doesn't refresh
pSection=m_pReport->Sections->GetItem("D"
pHeaderSection=m_pReport->Sections->GetItem("PH"
pFooterSection=m_pReport->Sections->GetItem("PF"
for (int j=0;j<3;j++) {
if (m_pobjHeader[j]!=NULL) pHeaderSection->DeleteObject(_variant_t(& *m_pobjHeader[j]));
if (m_pobjDetail[j]!=NULL) pSection->DeleteObject(_variant_t(& *m_pobjDetail[j]));
m_pobjHeader[j]=NULL; m_pobjDetail[j]=NULL;
}
if (m_pobjFooter!=NULL) pFooterSection->DeleteObject(_variant_t(& *m_pobjFooter));
m_pobjFooter=NULL;
// destroy report data
j=m_pReport->Database->Tables->GetCount();
while (j) {
m_pReport->Database->Tables->Delete(j);
j--;
}
m_pCryst->SetReportSource(NULL);
m_pCryst->DestroyWindow();
m_pReport->Release(); // HERE IS I'V GOT AN ERROR. HOW CAN I CLOSE OR
m_pReport=NULL; // DISCONNECT REPORT FROM ADO RECORDSET PROPERLY
// TO PREVENT DATABASE FROM STAYING LOCKED?
When I comment the last string ("m_pReport=NULL;", the database stay locked and the error appear
during recreating report at line commented with "***" ("m_pReport=m_pApplication->NewReport();".
Could anybody advise how can I destroy created report properly (since there is no such method as
CloseReport at IApplicationPtr, or related method) to reuse the m_pReport for the next report and
prevent database from staying locked? Thank you very much!
P.S. Where can I get entire documentation on Crystal Report Designer Component (RDC)?
I have a problems with closing reports during run-time using Crystal Report Designer Component (RDC) from
Crystal Repotrs 8.5 with Visual C++ 6.0. I have the following member variables defined in my appilication CWinApp-derived
class:
IApplicationPtr m_pApplication;
IReportPtr m_pReport;
IFieldObjectPtr m_pobjDetail[3]; // fields pointers array for three objects
ITextObjectPtr m_pobjHeader[3]; // text pointers array for three objects
ITextObjectPtr m_pobjFooter; // fields pointer for report footer
CCrystalReportViewer4* m_pCryst;
CAdodc m_ctlADODC; // Microsoft ADO Data Control
At application startup I'm initializing m_pApplication and creating CCrystalReportViewer4 object:
...
m_pApplication.CreateInstance("CrystalRuntime.Application"
m_pCryst=new CCrystalReportViewer4;
...
After that I'm creating ADO Data Control window. When user selects a new database, I'm setting new
ADO record source and creating new report during run-time at the following manner:
ISectionPtr pSection,pHeaderSection,pFooterSection;
ISectionPtr pGroupSection;
...
// get reference to my ADO recordset
CAdodc& refADO=m_ctlADODC;
C_Recordset& rc=refADO.GetRecordset();
// creating a new report (***)
m_pReport=m_pApplication->NewReport();
// add database to a report (THE REASON OF MY HEADACHE)
m_pReport->Database->Tables->Add("",vTemp,_variant_t((IDispatch *)rc.m_lpDispatch,true),vTemp,"p2smon.dll"
// get the Detail section using "D" and Header section using "PH" as the index
pSection=m_pReport->Sections->GetItem("D"
pHeaderSection=m_pReport->Sections->GetItem("PH"
pFooterSection=m_pReport->Sections->GetItem("PF"
// add data to the report's Header section
m_pobjHeader[0]=pHeaderSection->AddTextObject("Field1",400,0);
m_pobjHeader[1]=pHeaderSection->AddTextObject("Field2",1100,0);
m_pobjHeader[2]=pHeaderSection->AddTextObject("Field3",2900,0);
// add data to the report's Detail section
m_pobjDetail[0]=pSection->AddFieldObject("{ado.Field1}",400,0);
m_pobjDetail[1]=pSection->AddFieldObject("{ado.Field2}",1100,0);
m_pobjDetail[2]=pSection->AddFieldObject("{ado.Field3}",2900,0);
// add data to the report's Footer section
_bstr_t bstrMessage("My report footer"
m_pobjFooter=pFooterSection->AddTextObject(bstrMessage,0,0);
::SysFreeString(bstrMessage);
// pass the report to the viewer and preview the report
m_pCryst->SetReportSource(NULL);
m_pCryst->SetReportSource(m_pReport);
m_pCryst->Zoom(100);
m_pCryst->ViewReport();
...
Above code works fine and I can see a valid report.
When user closes current database, I'm trying to close ADO recordset and report:
C_Recordset& rc=m_ctlADODC.GetRecordset();
if (rc.m_lpDispatch!=NULL) rc.Close(); // close recordset if it wasn't closed previously
// destroy footer since it doesn't refresh
pSection=m_pReport->Sections->GetItem("D"
pHeaderSection=m_pReport->Sections->GetItem("PH"
pFooterSection=m_pReport->Sections->GetItem("PF"
for (int j=0;j<3;j++) {
if (m_pobjHeader[j]!=NULL) pHeaderSection->DeleteObject(_variant_t(& *m_pobjHeader[j]));
if (m_pobjDetail[j]!=NULL) pSection->DeleteObject(_variant_t(& *m_pobjDetail[j]));
m_pobjHeader[j]=NULL; m_pobjDetail[j]=NULL;
}
if (m_pobjFooter!=NULL) pFooterSection->DeleteObject(_variant_t(& *m_pobjFooter));
m_pobjFooter=NULL;
// destroy report data
j=m_pReport->Database->Tables->GetCount();
while (j) {
m_pReport->Database->Tables->Delete(j);
j--;
}
m_pCryst->SetReportSource(NULL);
m_pCryst->DestroyWindow();
m_pReport->Release(); // HERE IS I'V GOT AN ERROR. HOW CAN I CLOSE OR
m_pReport=NULL; // DISCONNECT REPORT FROM ADO RECORDSET PROPERLY
// TO PREVENT DATABASE FROM STAYING LOCKED?
When I comment the last string ("m_pReport=NULL;", the database stay locked and the error appear
during recreating report at line commented with "***" ("m_pReport=m_pApplication->NewReport();".
Could anybody advise how can I destroy created report properly (since there is no such method as
CloseReport at IApplicationPtr, or related method) to reuse the m_pReport for the next report and
prevent database from staying locked? Thank you very much!
P.S. Where can I get entire documentation on Crystal Report Designer Component (RDC)?