Solved

How do I serialize a form view?

Posted on 1999-01-29
2
227 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 50 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 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.

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

15 Experts available now in Live!

Get 1:1 Help Now