Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Importing selected data to an SDI document from an existing document

Posted on 1998-05-10
3
Medium Priority
?
190 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 100 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

824 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