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. Global Variables in SDI

Global Variables in SDI

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
25 Posts 7 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.
  • L LittleYellowBird

    CPallini wrote:

    If you include the header into exactly one source file then the linker will cheer you.

    That's what I do, I declare my global variable in a header called 'Globals.h', then include it just once! :thumbsup: Then I declare it as extern in Externs.h and include it wherever I want to use it ..... :) The linker is happy, but I thought you considered it a bad habit or bad style and I wondered why ..... maybe I missunderstood ...... :)

    Ali

    C Offline
    C Offline
    CPallini
    wrote on last edited by
    #16

    Well, if you define the global variable into a source file then you lower the probabilities of duplicate inclusion... :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    H 1 Reply Last reply
    0
    • H hellogany

      i solved it... but error occurs when i transfer the data to edit box... m_txtlog=g_MyVariable; UpdateData(FALSE); Error occurs while displayin

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #17

      hellogany wrote:

      Error occurs

      Which error ? Please be specific, we can't see what is displayed on your screen.

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • C CPallini

        Well, if you define the global variable into a source file then you lower the probabilities of duplicate inclusion... :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        H Offline
        H Offline
        hellogany
        wrote on last edited by
        #18

        Well While Debugging, i m able to get the value .... But couldnt able to display in edit control. Its throws Assertin Error

        C 1 Reply Last reply
        0
        • H hellogany

          Well While Debugging, i m able to get the value .... But couldnt able to display in edit control. Its throws Assertin Error

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #19

          Please post the (relevant) code. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          H 1 Reply Last reply
          0
          • H hellogany

            Ya.. i was tryin to use this.. This works well in Dialog Apps.. but am in SDi now ..Its throws Assertion Failed Error

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #20

            hellogany wrote:

            Its throws Assertion Failed Error

            What line of what file is asserting?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Man who follows car will be exhausted." - Confucius

            1 Reply Last reply
            0
            • H hellogany

              how does to update to textbox.. I am Able to get date... is UpdateData(FALSE) Works fine in SDI(FormView) ???

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #21

              hellogany wrote:

              is UpdateData(FALSE) Works fine in SDI(FormView) ???

              Why are you using UpdateData()? Without fully understanding what it does and how to use it, it will only cause you grief. Use SetWindowText() instead.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Man who follows car will be exhausted." - Confucius

              1 Reply Last reply
              0
              • C CPallini

                Please post the (relevant) code. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                H Offline
                H Offline
                hellogany
                wrote on last edited by
                #22

                m_txtlog=g_MyVariable; UpdateData(FALSE); m_txlog is the edit control i am using the above code in oncreate function...

                C 1 Reply Last reply
                0
                • H hellogany

                  m_txtlog=g_MyVariable; UpdateData(FALSE); m_txlog is the edit control i am using the above code in oncreate function...

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #23

                  You cannot do that in the on OnCreate method, since controls not yet exist. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  1 Reply Last reply
                  0
                  • L LittleYellowBird

                    CPallini wrote:

                    If you include the header into exactly one source file then the linker will cheer you.

                    That's what I do, I declare my global variable in a header called 'Globals.h', then include it just once! :thumbsup: Then I declare it as extern in Externs.h and include it wherever I want to use it ..... :) The linker is happy, but I thought you considered it a bad habit or bad style and I wondered why ..... maybe I missunderstood ...... :)

                    Ali

                    I Offline
                    I Offline
                    Iain Clarke Warrior Programmer
                    wrote on last edited by
                    #24

                    The problem here is that you have a terminology issue. You declare the variable in HEADER file (something.h) that can be freely included in SOURCE files (*.c / *.cpp)

                    extern int g_MyVariable

                    Where you and other have an issue is that you implement the variable in another .h file, that you actually treat like a source file. So, your compiler builds some cpp file, that is the only file including this special header. As long as you are disciplined about this, you'll be fine. But anyone else coming along will be puzzled. Some day you'll make a mistake... If you put the actual implementation

                    int g_MyVariable = 0;

                    in a source file, then you can't make this mistake. OK, you can, but any line like:

                    #include "globalvars.cpp"

                    is going to be really obvious. I hope that helps a little... Iain.

                    I have now moved to Sweden for love (awwww).

                    H 1 Reply Last reply
                    0
                    • I Iain Clarke Warrior Programmer

                      The problem here is that you have a terminology issue. You declare the variable in HEADER file (something.h) that can be freely included in SOURCE files (*.c / *.cpp)

                      extern int g_MyVariable

                      Where you and other have an issue is that you implement the variable in another .h file, that you actually treat like a source file. So, your compiler builds some cpp file, that is the only file including this special header. As long as you are disciplined about this, you'll be fine. But anyone else coming along will be puzzled. Some day you'll make a mistake... If you put the actual implementation

                      int g_MyVariable = 0;

                      in a source file, then you can't make this mistake. OK, you can, but any line like:

                      #include "globalvars.cpp"

                      is going to be really obvious. I hope that helps a little... Iain.

                      I have now moved to Sweden for love (awwww).

                      H Offline
                      H Offline
                      hellogany
                      wrote on last edited by
                      #25

                      Hi Thanks i solved it...

                      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