Thread: sharing variables between dialogs

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    sharing variables between dialogs

    Hi,
    I have a program with two dialog boxes each with their own class. If someone clicks on a button in Dialog A, it opens up dialog B. I was wondering is Dialog B will have access to the public variables in dialog A or if not, is there a way for Dialog A to pass variables to dialog B. Thanks
    Amish

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Given A is parent of B, then yes B has access to public members of A.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    To create dialog B, all I do is this:
    filterFileCreator dlg;
    dlg.DoModal();

    but in the class B, it does not seem like I have access to public functions and variables of class A

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Override DoModal() so that it looks like:
    DoModal(ClassA *parent)

    Then when you call it:
    filterFileCreator dlg;
    dlg.DoModal(this);

    In the DoModal() function you will need to call CDialog:: DoModal().

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    Class A #includes classB.h
    If I am to use the this pointer in class B, I will have to include ClassA.h in Class B. Wouldn't the classes including each other cause problem. Thanks
    Amish

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Use a forward reference:

    Code:
    // dialogB.h
    
    class DialogA;
    
    class DialogB
    {
         private: DialogA *pA;
         ...
    }
    
    ........
    
    // DialogA.h
    #include DialogB.h
    class DialogA 
    {
        private: DialogB db;
        ...
    }
    You can also consider placing the class definitions in the same header file since they seem to be tightly coupled together.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  2. Sharing variables and code architecture
    By JackR in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2007, 04:29 PM
  3. forking and sharing variables
    By Boomba in forum C Programming
    Replies: 2
    Last Post: 11-20-2005, 08:09 AM
  4. Sharing Variables
    By ljhr in forum C Programming
    Replies: 3
    Last Post: 09-09-2005, 03:56 PM
  5. Returning variables from dialogs
    By CPPguy1111 in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2005, 09:20 AM