Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Odd MFC Property Page Data Loss

Odd MFC Property Page Data Loss

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    switang
    wrote on last edited by
    #1

    I have a Property Sheet that has three pages. One of the pages contains some edit controls. I have all the data exchange functions set up, blah, blah, blah...and the sheet works great, all data gets exchanged and I can view the changes in the data before I delete the property sheet. OK. Here's where the problem occurs. I open a dialog box via AfxMessageBox() to warn the user of a failure before the property sheet and pages are deleted. Immediately after (line after the call to AfxMessageBox()) the dialog is closed the values in the edit controls are reverted back to the values when the property page was first opened. If I comment out the call to the messaged box, the data remains changed. I've stepped through most of the guts of AfxMessageBox() to find exactly when the data is reverted. Didn't really notice any changes in the data until after I click OK on the message box. Synopsis: - Open property sheet - change data on a page - click OK - Data is changed - Open message box to warn user - click OK on message box - Data is reverted No DDX functions seemed to be called during the call to AfxMessageBox(). Code: --------------------------------------------------------------------------------- ... //Change the printer values if (returnValue == IDOK) { **Data is CHANGED/UPDATED/STORED at this point** if (generalProperties != NULL) { //Printer Name printer->name->replace(0, MAX_STRING, generalProperties->name); ... } if (printerControlProperties != NULL) { //Assuming printer control properties was not open for // printers that don't have controls //Open the communication source PrinterControl * printerControl = printer->getPrinterControl(); _ASSERT(printerControl != NULL); //Check for failure if (!printerControl->openCommunicationSource((char *) printerControlProperties->connection.GetString())) { -----> AfxMessageBox( "Unable to open connection to printer control.", MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION, 0); **Data is REVERTED at this point** } } ... --------------------------------------------------------------------------------- End - Code

    S M 3 Replies Last reply
    0
    • S switang

      I have a Property Sheet that has three pages. One of the pages contains some edit controls. I have all the data exchange functions set up, blah, blah, blah...and the sheet works great, all data gets exchanged and I can view the changes in the data before I delete the property sheet. OK. Here's where the problem occurs. I open a dialog box via AfxMessageBox() to warn the user of a failure before the property sheet and pages are deleted. Immediately after (line after the call to AfxMessageBox()) the dialog is closed the values in the edit controls are reverted back to the values when the property page was first opened. If I comment out the call to the messaged box, the data remains changed. I've stepped through most of the guts of AfxMessageBox() to find exactly when the data is reverted. Didn't really notice any changes in the data until after I click OK on the message box. Synopsis: - Open property sheet - change data on a page - click OK - Data is changed - Open message box to warn user - click OK on message box - Data is reverted No DDX functions seemed to be called during the call to AfxMessageBox(). Code: --------------------------------------------------------------------------------- ... //Change the printer values if (returnValue == IDOK) { **Data is CHANGED/UPDATED/STORED at this point** if (generalProperties != NULL) { //Printer Name printer->name->replace(0, MAX_STRING, generalProperties->name); ... } if (printerControlProperties != NULL) { //Assuming printer control properties was not open for // printers that don't have controls //Open the communication source PrinterControl * printerControl = printer->getPrinterControl(); _ASSERT(printerControl != NULL); //Check for failure if (!printerControl->openCommunicationSource((char *) printerControlProperties->connection.GetString())) { -----> AfxMessageBox( "Unable to open connection to printer control.", MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION, 0); **Data is REVERTED at this point** } } ... --------------------------------------------------------------------------------- End - Code

      S Offline
      S Offline
      switang
      wrote on last edited by
      #2

      If I move the message so that I displays after I store the data in another object, I am good. But the funny thing is that it doesn't revert the data if the call is further down in the code....:confused: -- modified at 12:59 Thursday 16th November, 2006

      1 Reply Last reply
      0
      • S switang

        I have a Property Sheet that has three pages. One of the pages contains some edit controls. I have all the data exchange functions set up, blah, blah, blah...and the sheet works great, all data gets exchanged and I can view the changes in the data before I delete the property sheet. OK. Here's where the problem occurs. I open a dialog box via AfxMessageBox() to warn the user of a failure before the property sheet and pages are deleted. Immediately after (line after the call to AfxMessageBox()) the dialog is closed the values in the edit controls are reverted back to the values when the property page was first opened. If I comment out the call to the messaged box, the data remains changed. I've stepped through most of the guts of AfxMessageBox() to find exactly when the data is reverted. Didn't really notice any changes in the data until after I click OK on the message box. Synopsis: - Open property sheet - change data on a page - click OK - Data is changed - Open message box to warn user - click OK on message box - Data is reverted No DDX functions seemed to be called during the call to AfxMessageBox(). Code: --------------------------------------------------------------------------------- ... //Change the printer values if (returnValue == IDOK) { **Data is CHANGED/UPDATED/STORED at this point** if (generalProperties != NULL) { //Printer Name printer->name->replace(0, MAX_STRING, generalProperties->name); ... } if (printerControlProperties != NULL) { //Assuming printer control properties was not open for // printers that don't have controls //Open the communication source PrinterControl * printerControl = printer->getPrinterControl(); _ASSERT(printerControl != NULL); //Check for failure if (!printerControl->openCommunicationSource((char *) printerControlProperties->connection.GetString())) { -----> AfxMessageBox( "Unable to open connection to printer control.", MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION, 0); **Data is REVERTED at this point** } } ... --------------------------------------------------------------------------------- End - Code

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        AfxMessageBox() shouldn't change any data but is anything going on in the calls leading up to it, like printerControl->openCommunicationSource(...) ??

        S 1 Reply Last reply
        0
        • M Mark Salsbery

          AfxMessageBox() shouldn't change any data but is anything going on in the calls leading up to it, like printerControl->openCommunicationSource(...) ??

          S Offline
          S Offline
          switang
          wrote on last edited by
          #4

          openCommunicationSource() is totally disjunct from the page. It's parameter is just receiving a combo-box's value.

          M 1 Reply Last reply
          0
          • S switang

            I have a Property Sheet that has three pages. One of the pages contains some edit controls. I have all the data exchange functions set up, blah, blah, blah...and the sheet works great, all data gets exchanged and I can view the changes in the data before I delete the property sheet. OK. Here's where the problem occurs. I open a dialog box via AfxMessageBox() to warn the user of a failure before the property sheet and pages are deleted. Immediately after (line after the call to AfxMessageBox()) the dialog is closed the values in the edit controls are reverted back to the values when the property page was first opened. If I comment out the call to the messaged box, the data remains changed. I've stepped through most of the guts of AfxMessageBox() to find exactly when the data is reverted. Didn't really notice any changes in the data until after I click OK on the message box. Synopsis: - Open property sheet - change data on a page - click OK - Data is changed - Open message box to warn user - click OK on message box - Data is reverted No DDX functions seemed to be called during the call to AfxMessageBox(). Code: --------------------------------------------------------------------------------- ... //Change the printer values if (returnValue == IDOK) { **Data is CHANGED/UPDATED/STORED at this point** if (generalProperties != NULL) { //Printer Name printer->name->replace(0, MAX_STRING, generalProperties->name); ... } if (printerControlProperties != NULL) { //Assuming printer control properties was not open for // printers that don't have controls //Open the communication source PrinterControl * printerControl = printer->getPrinterControl(); _ASSERT(printerControl != NULL); //Check for failure if (!printerControl->openCommunicationSource((char *) printerControlProperties->connection.GetString())) { -----> AfxMessageBox( "Unable to open connection to printer control.", MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION, 0); **Data is REVERTED at this point** } } ... --------------------------------------------------------------------------------- End - Code

            S Offline
            S Offline
            switang
            wrote on last edited by
            #5

            It may have something to do with me not using SetModified()... -- modified at 12:58 Thursday 16th November, 2006

            1 Reply Last reply
            0
            • S switang

              openCommunicationSource() is totally disjunct from the page. It's parameter is just receiving a combo-box's value.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Are using SetModified() when the user changes any items in the dialog? The code you posted is in an OnKillActive() override? If using DDX are you calling UpdateData() where appropriate?

              S 2 Replies Last reply
              0
              • M Mark Salsbery

                Are using SetModified() when the user changes any items in the dialog? The code you posted is in an OnKillActive() override? If using DDX are you calling UpdateData() where appropriate?

                S Offline
                S Offline
                switang
                wrote on last edited by
                #7

                I'm am not using SetModified(). I have OnKillActive() and OnSetActive() overridden to only return TRUE to prevent the changes in the pages from being reverted by the DDX calls when switching between pages (tabs). Will SetModified(TRUE), fix this? I'm using UpdateData() on my overridden OnOK(), since for some reason the data wasn't being updated (probably due to me not using SetModified()). I'll try to incorporate SetModified() (which I need to do anyways) and get back with you. Having to redesign a little to accommodate the Apply functionality.

                1 Reply Last reply
                0
                • M Mark Salsbery

                  Are using SetModified() when the user changes any items in the dialog? The code you posted is in an OnKillActive() override? If using DDX are you calling UpdateData() where appropriate?

                  S Offline
                  S Offline
                  switang
                  wrote on last edited by
                  #8

                  OK I've modified a few things to handle the Apply functionality, and I am using SetModified(). Everything looks good except, If I apply a change, and then click Cancel, the changes are not updated. I read that OnApply() just calls OnOK(), which calls UpdateData(TRUE), so why are my changes being reverted? If I make a change and click OK, my changes are stored. I'm used to Apply storing changes, regardless of clicking OK or Cancel.

                  M S 2 Replies Last reply
                  0
                  • S switang

                    OK I've modified a few things to handle the Apply functionality, and I am using SetModified(). Everything looks good except, If I apply a change, and then click Cancel, the changes are not updated. I read that OnApply() just calls OnOK(), which calls UpdateData(TRUE), so why are my changes being reverted? If I make a change and click OK, my changes are stored. I'm used to Apply storing changes, regardless of clicking OK or Cancel.

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    switang wrote:

                    If I apply a change, and then click Cancel, the changes are not updated

                    Sounds like it's working like it's "supposed" to :) To save changes on cancel (not what a user would expect) you'd ned to do the same thing in OnCancel() that you do in your OnOk() (or wherever you are committing the changes). Instead of duplicating the code you can add a function that does all the saving and call it from both places.

                    1 Reply Last reply
                    0
                    • S switang

                      OK I've modified a few things to handle the Apply functionality, and I am using SetModified(). Everything looks good except, If I apply a change, and then click Cancel, the changes are not updated. I read that OnApply() just calls OnOK(), which calls UpdateData(TRUE), so why are my changes being reverted? If I make a change and click OK, my changes are stored. I'm used to Apply storing changes, regardless of clicking OK or Cancel.

                      S Offline
                      S Offline
                      switang
                      wrote on last edited by
                      #10

                      Never mind. In the midst of restructuring the property pages, I forgot I was still updating the properties outside of the actual property page class. And plus I wasn't overriding OnOK() to update the data. :doh: Still don't know about the message box. Hopefully it won't bother me with the new structure.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups