Solved

Importing selected data to an SDI document from an existing document

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now