Solved

Importing selected data to an SDI document from an existing document

Posted on 1998-05-10
3
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

Suggested Solutions

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…
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…
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.

710 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