Solved

How do I serialize a form view?

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

840 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