Solved

Importing selected data to an SDI document from an existing document

Posted on 1998-05-10
3
183 Views
Last Modified: 2010-04-10
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_OVERWRITEPROMPT,
  "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(pathname), 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(...)
         {

         }
    }
}
0
Comment
Question by:fatfrank
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 50 total points
ID: 1175402
You algorithm looks OK to me .. but I'd try instead I wouldn't do anything to the doc templates, or manually open the input file

Simply create a document with new (as you have done).

Then open the file using OnOpenDocument(pathname,false)

That will serialize.

Then, after extracting what you want. call OnCloseDocument to close it (which will close the file and kill off the document.

I do this myself to read in a 'library' file as a document (with library items in it) so the user can pick items from it and copy them into the main document.


0
 

Author Comment

by:fatfrank
ID: 1175403
The answer give by ronslow did not work! A CDocument object does not have a function OnOpenDocument(pathname,false) though the SingleDocument template does. I eventually solved the problem by debuging onto the MFC code for an OLE derived document.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1175404
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??

0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question