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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to avoid a Global Variable

How to avoid a Global Variable

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 3 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.
  • M Offline
    M Offline
    Madhu_Rani
    wrote on last edited by
    #1

    Hi, I have an SDI application and in view class, I call a dialog by using dlg.DoModal(); There is an EditBox in the dialog and I want to use the entered value in the view class. Now one way is that I declar a global variable and store the value in it. or declare a varibale in App class and use that variable. Is any other fine way to do the stuff and I may avoid variable at application level/global? THANKS

    C R 2 Replies Last reply
    0
    • M Madhu_Rani

      Hi, I have an SDI application and in view class, I call a dialog by using dlg.DoModal(); There is an EditBox in the dialog and I want to use the entered value in the view class. Now one way is that I declar a global variable and store the value in it. or declare a varibale in App class and use that variable. Is any other fine way to do the stuff and I may avoid variable at application level/global? THANKS

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      something like this ?

      void CMyView::SomeFunc()
      {
      CMyDialog dlg;

      if (dlg.DoModal() == IDOK)
      {
      m_myVar = dlg.m_editVar;
      }
      }

      image processing toolkits | batch image processing

      1 Reply Last reply
      0
      • M Madhu_Rani

        Hi, I have an SDI application and in view class, I call a dialog by using dlg.DoModal(); There is an EditBox in the dialog and I want to use the entered value in the view class. Now one way is that I declar a global variable and store the value in it. or declare a varibale in App class and use that variable. Is any other fine way to do the stuff and I may avoid variable at application level/global? THANKS

        R Offline
        R Offline
        Rick York
        wrote on last edited by
        #3

        You can also pass the old value to its constructor as the initial value and make a "Get" method in the dialog class to return the new value.

        M 1 Reply Last reply
        0
        • R Rick York

          You can also pass the old value to its constructor as the initial value and make a "Get" method in the dialog class to return the new value.

          M Offline
          M Offline
          Madhu_Rani
          wrote on last edited by
          #4

          THANKS both of you.

          M 1 Reply Last reply
          0
          • M Madhu_Rani

            THANKS both of you.

            M Offline
            M Offline
            Madhu_Rani
            wrote on last edited by
            #5

            void CMyView::SomeFunc() { CMyDialog dlg; if (dlg.DoModal() == IDOK) { m_myVar = dlg.m_editVar; } } This works fine for OK button but does not work for other buttons such as Connect having id IDCONNECT... any idea why? if (dlg.DoModal()==IDCONNECT) {// does not work }

            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