fatfrank
asked on
Importing selected data to an SDI document from an existing document
I want to import data selectively from an existing SDI document but can't
seem to get the right way to read a second document. Ive tried creating a
new document template and can successfully get the import data, but the
process trashes my existing dialog or view pointers meaning I can't pass the
data back to the calling view (The app is a bit complicated with CDocument
etc all in DLLs).
Can anyone explain why this might happen or alternatively why the following
will not work, it just returns garbage!
Thanks in advance.
Mark Conlin
CFileDialog dlg(TRUE, "*cit", "*.cit",
OFN_HIDEREADONLY|OFN_OVERW RITEPROMPT ,
"CITS Calc Files (*.cit)|*.cit");
if(dlg.DoModal() == IDOK)
{
CString pathname = dlg.GetPathName();
// if the file exists then open it and read in the data
if (pathname != "")
{
CFile theFile;
theFile.Open(LPCTSTR(pathn ame), CFile::modeRead);
CArchive archive(&theFile, CArchive::load);
CCITSDoc* pDoc = new CCITSDoc;
try
{
TRACE("Object schema = %d\n", archive.GetObjectSchema()) ;
pDoc->Serialize(archive);
... pick out the required data from the documment
here.......
}
catch(...)
{
}
}
}
seem to get the right way to read a second document. Ive tried creating a
new document template and can successfully get the import data, but the
process trashes my existing dialog or view pointers meaning I can't pass the
data back to the calling view (The app is a bit complicated with CDocument
etc all in DLLs).
Can anyone explain why this might happen or alternatively why the following
will not work, it just returns garbage!
Thanks in advance.
Mark Conlin
CFileDialog dlg(TRUE, "*cit", "*.cit",
OFN_HIDEREADONLY|OFN_OVERW
"CITS Calc Files (*.cit)|*.cit");
if(dlg.DoModal() == IDOK)
{
CString pathname = dlg.GetPathName();
// if the file exists then open it and read in the data
if (pathname != "")
{
CFile theFile;
theFile.Open(LPCTSTR(pathn
CArchive archive(&theFile, CArchive::load);
CCITSDoc* pDoc = new CCITSDoc;
try
{
TRACE("Object schema = %d\n", archive.GetObjectSchema())
pDoc->Serialize(archive);
... pick out the required data from the documment
here.......
}
catch(...)
{
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops , that 'false' shouldn't have been there. sorry.
However, CDocument DOES indeed have an OnOpenDocument function .. check the documentation on CDocument. It says that "The default implementation of this function opens the specified file, calls the DeleteContents member function to ensure that the document is empty, calls CObject::Serialize to read the file's contents, and then marks the document as clean"
The method I suggested DOES work because I use it myself (with OLE derived documents). Perhaps what you should have said was the you could not get it to work. In which case you could have asked me for help on how to do it, rather than simply proclaiming it as not working.
BTW: What ended up being your problem??
However, CDocument DOES indeed have an OnOpenDocument function .. check the documentation on CDocument. It says that "The default implementation of this function opens the specified file, calls the DeleteContents member function to ensure that the document is empty, calls CObject::Serialize to read the file's contents, and then marks the document as clean"
The method I suggested DOES work because I use it myself (with OLE derived documents). Perhaps what you should have said was the you could not get it to work. In which case you could have asked me for help on how to do it, rather than simply proclaiming it as not working.
BTW: What ended up being your problem??
ASKER