-
July 27th, 2004, 03:23 PM
#1
Updating CDocument data from view
Hi,
I'm writing a SDI app. which has edit/combobox/list controls on the CFormView based dialog. All the controls have a variable (CString most of them) on the CDocument class waiting to receive their values. What would be the best way to update these variables before serialize them using the "Save" button on the toolbar? Should i map messages like ON_CBN_KILLFOCUS for each control and update them one by one? Or should i get, somehow, these values from the CDocument itself inside the serialize function?
Thanks in advance.
Ric
P.S. I'm new on SDI/MDI. Dialog based app so far.]
P.S.2 I researched the forum but didn't find any clarification on this.
-
July 27th, 2004, 03:28 PM
#2
MSDN says
Implement a member function to move data from your view to your document.
This member function is typically a message handler for a control-notification message or for a menu command. If you are using DDX, call the UpdateData member function to update the member variables in your view class. Then move their values to the document associated with the form view.
-
July 27th, 2004, 04:06 PM
#3
Ok. Let's say I have the OnFileSave handler (for the toolbar "save" button) inside my cview class. I write my code so that the variables in the Cdocument are updated. How can I keep calling the OnFileSave/Serialize handler in the CDocument?Is that possible? I've read that the the application framework starts looking for message handlers in the view/document sequence. I'd like to avoid having to push other button besides the Save one.
Thanks again,
Ric
-
July 27th, 2004, 05:16 PM
#4
Usually form view is used to collect data from user.
Use Serialize member of the view to store form’s data.
Call that member from Serialize member of the document.
After view’s data is retrieved from file use data members of the view to initialize members of the document if needed.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
July 28th, 2004, 06:00 AM
#5
I'm using the form to get user data, just that. However I do some sort of processing (very simple) before saving data to disk and my intention was to have this processing under the serialize function on CDocument, so I need the updated values from controls.
Since I hava some more info. to save, not from view, I would like to avoid calling calling view->serialize from CDocument (if I undestood correctly John's post )
Currently I update the Cdocument variables (associated to the form controls) everytime each control looses focus. But I do know this is not the best approach.
Any other idea? Thanks once more.
Ric
-
July 28th, 2004, 07:10 AM
#6
Originally Posted by RIC_V
Ok. Let's say I have the OnFileSave handler (for the toolbar "save" button) inside my cview class. I write my code so that the variables in the Cdocument are updated. How can I keep calling the OnFileSave/Serialize handler in the CDocument?Is that possible? I've read that the the application framework starts looking for message handlers in the view/document sequence. I'd like to avoid having to push other button besides the Save one.
Thanks again,
Ric
You can call CDocument::OnSaveDocument() any time you like.
-
July 28th, 2004, 09:14 AM
#7
I called CDocument::OnSaveDocument() from my view as suggested. I endup having to implement the dialog for getting user file name/directory myself (if I didn't miss something here).
Since I would like to keep the default behaviour (i.e. having the framework handle this) I was thinking about building a funcion (inside my CFormview) which will be in charge of updating the variables in the document. So everytime the user save the data, I call this function from CDocument, just before serialize them. Do you guys see any problem with that?
Regards,
Ric
-
July 28th, 2004, 09:33 AM
#8
Originally Posted by RIC_V
I called CDocument::OnSaveDocument() from my view as suggested. I endup having to implement the dialog for getting user file name/directory myself (if I didn't miss something here).
Since I would like to keep the default behaviour (i.e. having the framework handle this) I was thinking about building a funcion (inside my CFormview) which will be in charge of updating the variables in the document. So everytime the user save the data, I call this function from CDocument, just before serialize them. Do you guys see any problem with that?
Regards,
Ric
That's what MSDN suggested in the quote I posted almost. Just write an ID_FILE_SAVE handler in the view, call UpdateData(), then call the default handler.
-
July 28th, 2004, 10:55 AM
#9
Didn't find a way to call the "default Handler" which i assumed was the handler in the CDocument Class (protected). What I did was to change the ID for the "Save button", add a handler for it (where I finally do my update) and then post a message calling the "default handler".
PostMessage( WM_COMMAND, ID_FILE_SAVE );
It's working as intended.
Thank you all.
Ric
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|