Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I serialize a form view?

Posted on 1999-01-29
2
Medium Priority
?
275 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
[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 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

Independent Software Vendors: 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

715 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