Print Page | Close Window

CArchive, bad index?!

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=9519
Printed Date: 27 September 2024 at 3:50pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CArchive, bad index?!
Posted By: znakeeye
Subject: CArchive, bad index?!
Date Posted: 06 February 2008 at 8:36pm
Hi,
 
I have derived from CXTTreeCtrl and COleDropTarget. Then I registered a clipboard format in my report control and catch it in CMyTreeCtrl::OnDrop. Dragging ONE row from the report control succeeds, but when dragging multiple rows, the second one causes an exception at the call to PX_Object (CArchiveException::badIndex).
 
What am I doing wrong?
 
BOOL CMyTreeCtrl::OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point)
{
 if (!pDataObject->IsDataAvailable(m_cfFormat))
  return FALSE;
 
 CFile* pFile = pDataObject->GetFileData(m_cfFormat);
 if (!pFile)
  return FALSE;
 CXTPReportRecords arRecords;
 CArchive ar(pFile, CArchive::load);
 
 try
 {
  CXTPPropExchangeArchive px(ar);
 
  CXTPPropExchangeSection secRecords(px.GetSection(_T("ReportRecords")));
  
  long nSchema = 0;
  
  PX_Long(&px, _T("Version"), (long&)nSchema);
  px.ExchangeLocale();
  
  CXTPPropExchangeEnumeratorPtr pEnumRecords(secRecords->GetEnumerator(_T("Record")));
  POSITION posRecord = pEnumRecords->GetPosition();
  while (posRecord)
  {
   CXTPPropExchangeSection secRecord(pEnumRecords->GetNext(posRecord));
   
   CXTPReportRecord* pRecord = NULL;
   PX_Object(&secRecord, pRecord, RUNTIME_CLASS(CXTPReportRecord));
   
   if (!pRecord)
    AfxThrowArchiveException(CArchiveException::badClass);
   
   CMyIndexRecordItem *pItem = DYNAMIC_DOWNCAST(CMyIndexRecordItem, pRecord->GetItem(1));
   if (pItem)
    InsertItem(pItem->GetValue());
   CMDTARGET_RELEASE(pRecord);
  }
 }
 catch (CArchiveException* pE)
 {
  pE->Delete();
 }
 catch (CFileException* pE)
 {
  pE->Delete();
 }
 catch (...)
 {
 }
 
 ar.Close();
 delete pFile;
 
 return TRUE;
}



Replies:
Posted By: znakeeye
Date Posted: 07 February 2008 at 10:38am
This code was copied from CXTPReportControl::Paste. I really can't understand why it won't work for N>1 items.
 
Please help me out.


Posted By: znakeeye
Date Posted: 07 February 2008 at 2:42pm
Ok, solved it. It turned out the code copied from the report sample had a minor error in it:
 
IMPLEMENT_SERIAL(CMyRecord, CXTPReportRecord, 0)
should be:
IMPLEMENT_SERIAL(CMyRecord, CXTPReportRecord, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
 
Quite amazing how such a small mistake can cause such hard-to-find errors.
 
Anyway, now I can drop my records on my tree control! \o/



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net