Solved

Importing selected data to an SDI document from an existing document

Posted on 1998-05-10
3
185 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

680 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