Dialogue destruction and member variable existence

Posted on 2004-04-02
Last Modified: 2013-11-20
Hello !

Quick question about calling DoModal() and the availability of dialogue member variables:

If I say

MyDialogue dlg

if (dlg.DoModal == IDOK) {
   CString s = dlg.m_str;
   int i = dlg.m_i;
   // etc etc etc.. other access of dlg member variables
// *

Now, when is the destructor for dlg called, hence up to what point can I access *true* (i.e. not garbage) values like dlg.m_str ?  I put a TRACE statement in my destructor for the dialog class, but it never got displayed !  Also I could still access dlg member variables at the point marked *; well after when I initially figured the dialogue would have been destroyed !

Question by:mrwad99
  • 3
  • 2
LVL 19

Accepted Solution

Dexstar earned 75 total points
ID: 10743227

> Now, when is the destructor for dlg called, hence up to what point can I access
> *true* (i.e. not garbage) values like dlg.m_str ?

The destructor gets called when the object falls out of scope.  If MyDialogue is a local variable in a function, you should be able to access those values throughout the entire function.  Do not get confused about the object that represents the dialog, and the dialog on the screen.  The dialog on the screen gets destroyed before DoModal() returns.  The object that represents it doesn't get destroyed until it falls out of scope.

Hope That Helps,
LVL 19

Author Comment

ID: 10743293
Four minutes; you are getting better...

LVL 19

Expert Comment

ID: 10743339

> Four minutes; you are getting better...

Heh.  Thanks!  :)

LVL 19

Author Comment

ID: 10746949

some time after I closed this question last night (GMT) I realised that nothing I had said actually even insinuated "thanks for answering my question".  So here it is:

Thanks !

PS Thanks also for the link on your profile to; I had a listen and they certainly are phat beats !

LVL 19

Expert Comment

ID: 10748303

You're welcome and you're welcome.  :)

Which stream did you like the best?  I usually listen to Trance or Vocal Trance, but I keep them all in the rotation.  Whatever my mood calls for.  :)


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 130
Question regarding Copy/Paste 16 96
Folder Comparison 12 54
Increment column based of a FK 8 30
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…

766 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