Solved

How do I serialize a form view?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 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.

919 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

21 Experts available now in Live!

Get 1:1 Help Now