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. Windows Forms Application C++ .net 2003

Windows Forms Application C++ .net 2003

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++winformshelp
7 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.
  • W Offline
    W Offline
    wael_r
    wrote on last edited by
    #1

    Pleaseeeeeeeeee can any one help me to declare public struct or variable to use in all the forms in "Windows Forms Application C++" ex: i want to declare a connection and use it in all the forms. i want to declare a structure and use it in all the forms.

    L S 2 Replies Last reply
    0
    • W wael_r

      Pleaseeeeeeeeee can any one help me to declare public struct or variable to use in all the forms in "Windows Forms Application C++" ex: i want to declare a connection and use it in all the forms. i want to declare a structure and use it in all the forms.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Declare it as static class member in one of the classes.

      1 Reply Last reply
      0
      • W wael_r

        Pleaseeeeeeeeee can any one help me to declare public struct or variable to use in all the forms in "Windows Forms Application C++" ex: i want to declare a connection and use it in all the forms. i want to declare a structure and use it in all the forms.

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        In a .h file (let's call it my_global_struct.h):

        #if !defined(__my_global_struct_h__)
        #define __my_global_struct_h__

        struct my_global_struct
        {
        // put whatever you want in the struct here
        };

        extern my_global_struct;

        #endif // !defined(__my_global_struct_h__)

        In a .cpp file (let's call it my_global_struct.cpp):

        #include my_global_struct.h
        my_global_struct;

        #include my_global_struct.h into any files that need to see the global struct variable.

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        W 1 Reply Last reply
        0
        • S Stuart Dootson

          In a .h file (let's call it my_global_struct.h):

          #if !defined(__my_global_struct_h__)
          #define __my_global_struct_h__

          struct my_global_struct
          {
          // put whatever you want in the struct here
          };

          extern my_global_struct;

          #endif // !defined(__my_global_struct_h__)

          In a .cpp file (let's call it my_global_struct.cpp):

          #include my_global_struct.h
          my_global_struct;

          #include my_global_struct.h into any files that need to see the global struct variable.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          W Offline
          W Offline
          wael_r
          wrote on last edited by
          #4

          Thank you very much for your reply but i need to user the same structure with the filled values in other form.

          S 1 Reply Last reply
          0
          • W wael_r

            Thank you very much for your reply but i need to user the same structure with the filled values in other form.

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            And there's nothing in my answer preventing you from doing so

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            W 1 Reply Last reply
            0
            • S Stuart Dootson

              And there's nothing in my answer preventing you from doing so

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              W Offline
              W Offline
              wael_r
              wrote on last edited by
              #6

              Thanks again, I tried your solution but may i need another thing. Ex: struct ggg{ int i; int j; }test; in the first form1 i put "test fff;" fff.i=1; in the second form i want to use the value of the same structure fff. Ex: i want in the form2 to give the value of fff.i to another variable in form2; any solution? really i spend one day on this. :sigh:

              S 1 Reply Last reply
              0
              • W wael_r

                Thanks again, I tried your solution but may i need another thing. Ex: struct ggg{ int i; int j; }test; in the first form1 i put "test fff;" fff.i=1; in the second form i want to use the value of the same structure fff. Ex: i want in the form2 to give the value of fff.i to another variable in form2; any solution? really i spend one day on this. :sigh:

                S Offline
                S Offline
                Stuart Dootson
                wrote on last edited by
                #7

                wael_r wrote:

                in the first form1 i put "test fff;"

                If you put test fff; in the form, then it's a member of the form class. So, you'd need to access it using an instance of the first form. If you want to share fff across all instances of form1 and form2, then you could make fff a static (or class-wide) member[^] of form1 - like this:

                class Form1
                {
                // Other stuff
                public: static test fff;
                };

                In Form1, you need to have a definition for fff (hte above is just the declaration like this:

                test Form1::fff = { 1, 2 };

                In form2, you can access it like this (I'm doing it in the constructor):

                Form2::Form2()
                {
                this->other_variable = Form1::fff.i;
                }

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                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