CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2011
    Posts
    16

    global variables

    How do I create global variable for dialog class (global object of dialog class), which is accessible to all other classes including other dialog classes?

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: global variables

    Put the variable in the public section.

  3. #3
    Join Date
    Apr 2011
    Posts
    16

    Re: global variables

    but public section of which class or file?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: global variables

    Did you mean "global" or static variable for dialog class?
    If former - then why?
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2011
    Posts
    16

    Re: global variables

    I need global variables or objects of dialog class for eg:- if my dialog class is dlg1 then I need the object as dlg1 d1 globally so that i can directly access d1 in other dialog classes such as dlg2, dlg3 etc.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: global variables

    Do you mean the "dialog classes" or " dialog class instances"?
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2011
    Posts
    16

    Re: global variables

    dlg1, dlg2 etc. are the names given to dialogbox class & d1,d2... are the instances of dlg1,dlg2...
    & I want to declare d1,d2 globally

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: global variables

    1. http://www.codeguru.com/forum/showthread.php?t=221889
    2. Usually declaring globals is not a good idea. In the most of cases (at least 99.99%) globals can be and should be avoided.
    What is the purpose to access dlg1 d1 from within other dialog classes such as dlg2, dlg3 etc.?
    Victor Nijegorodov

  9. #9
    Join Date
    Apr 2011
    Posts
    16

    Re: global variables

    I want to show dlg1 dialog from dlg2 & dlg3 on button
    click

  10. #10
    Join Date
    Apr 1999
    Posts
    27,449

    Re: global variables

    Quote Originally Posted by shwetashah01 View Post
    I want to show dlg1 dialog from dlg2 & dlg3 on button
    So why do you need a global variable for this? Just declare one locally and call DoModal().
    Code:
    dlg2::OnOk()
    {
        dlg1 myDlg;
        myDlg.DoModal();
       // ....
    }
    Given your description, I see no need for global variables whatsoever if all you want to do is invoke a dialog from another dialog.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured