CArchive, bad index?! |
Post Reply |
Author | |
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
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; } |
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
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.
|
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
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/ |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |