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

x
?
Solved

How do I serialize a form view?

Posted on 1999-01-29
2
Medium Priority
?
279 Views
Last Modified: 2010-05-18
I have an MDI application with a CFormView for a main window.  There are a dozen or so CEdit edit control boxes on the form.  How can I serialize the form to save the contents of the boxes to a file (and, of course, deserialize it again)?  This wouldn't be a database situation as each saved form would have its own contents.  It seems so easy but I've tried a lot of things and just can't get it to work.  Please be as specific as possible.  Thanks in advance.
0
Comment
Question by:jjjkkklll
2 Comments
 
LVL 1

Accepted Solution

by:
jim_pettinato earned 150 total points
ID: 1185512
You typically don't serialize a form... you serialize the document that is displayed by the form. Create a document class that has a member CString for each of the edit boxes.  There are a couple ways to update your document. The easiest is probably to handle the ON_EN_CHANGE notification from your edit controls in the form message map by adding this line:

  ON_EN_CHANGE(ID_EDIT_CTRLX, OnDataChanged)

Of course, you'll need to add the OnDataChanged code to get the text out of the controls and into the document. Then just override the document's Serialize() method to store the string data. With this method, the OnDataChanged code is going to have to get a pointer to each edit control, fetch the text, and assign it to the CString member in the document. (Note: with 12 edit controls, you may not want to read all of them each time any one is changed. In that case, you would need an ON_EN_CHANGED entry for each control, and a unique function to handle updating the data for that control).

Another approach is to derive your own view class from CFormView and override the DoDataExchange() member. Just define a member CString for each edit box on the form in your CFormView derived class, and in your DoDataExchange(), add a DDX_Text() entry pairing the CString member with the associated edit box. Then the form will update the member strings as they are edited. You still will need some way of moving the data into the document's members before serializing the document. Typically, the ON_EN_CHANGE message is still used to do that...  In this case the OnDataChanged() function would just call UpdateData() to read the data from the form's controls into the form's member strings, then copy the data in the form's member CStrings into the document's member CStrings.
0
 

Author Comment

by:jjjkkklll
ID: 1185513
Thanks, Jim.  I'll study this.  May have more questions (and/or answers) forthcoming.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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

926 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