MFC - Problem with serialization, previous contents of list is shown when selecting 'new' or 'openfile'
-
when I execute my simple program that I have implmented serialization with. scenario: I go about drawing a few shapes, which are added to my element list, and then save the file, which it successfuly does but a problem occurs when I select "new" or "open file": The previous content is still shown on 'new' and also with a the opened file: So I have then added code to the mfc-document "onNewDocument()" to delete all the elements in the list. And I have also added the code to remove all the elements as well to the virtual function I have added "OpenDocument" which also works fine. My only problem know is, if I save a document, and then do some extra drwaing, and then try to reload the the last save, the current drawing I am doing, remains, and the saved document remains unseen. Can anybody know why this implkmentation is not working, my understanding that mfc serialzation automatcaly takes care of these automatically Thanks V much if you can help Simon
-
when I execute my simple program that I have implmented serialization with. scenario: I go about drawing a few shapes, which are added to my element list, and then save the file, which it successfuly does but a problem occurs when I select "new" or "open file": The previous content is still shown on 'new' and also with a the opened file: So I have then added code to the mfc-document "onNewDocument()" to delete all the elements in the list. And I have also added the code to remove all the elements as well to the virtual function I have added "OpenDocument" which also works fine. My only problem know is, if I save a document, and then do some extra drwaing, and then try to reload the the last save, the current drawing I am doing, remains, and the saved document remains unseen. Can anybody know why this implkmentation is not working, my understanding that mfc serialzation automatcaly takes care of these automatically Thanks V much if you can help Simon
-
when I execute my simple program that I have implmented serialization with. scenario: I go about drawing a few shapes, which are added to my element list, and then save the file, which it successfuly does but a problem occurs when I select "new" or "open file": The previous content is still shown on 'new' and also with a the opened file: So I have then added code to the mfc-document "onNewDocument()" to delete all the elements in the list. And I have also added the code to remove all the elements as well to the virtual function I have added "OpenDocument" which also works fine. My only problem know is, if I save a document, and then do some extra drwaing, and then try to reload the the last save, the current drawing I am doing, remains, and the saved document remains unseen. Can anybody know why this implkmentation is not working, my understanding that mfc serialzation automatcaly takes care of these automatically Thanks V much if you can help Simon
You may be approaching this wrong. First, since you didn't say, I'm guessing that you have an SDI application. If that's the case, the document is never destroyed until the application exits. When you choose "new" or "open" the framework calls the CDocument's DeleteContents() function. You need to override that and clean up any previous work or data you may have created - basically, return all values to the point they would be when you first open the application. Hope that helps.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
modified on Thursday, August 20, 2009 6:32 AM
-
You may be approaching this wrong. First, since you didn't say, I'm guessing that you have an SDI application. If that's the case, the document is never destroyed until the application exits. When you choose "new" or "open" the framework calls the CDocument's DeleteContents() function. You need to override that and clean up any previous work or data you may have created - basically, return all values to the point they would be when you first open the application. Hope that helps.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
modified on Thursday, August 20, 2009 6:32 AM
thanks, what you said helps Simon