Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - CArchive, bad index?!
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CArchive, bad index?!

 Post Reply Post Reply
Author
Message
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Topic: CArchive, bad index?!
    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;
}
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post 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/
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.