Thread: passing a Struct from one Form to another?

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    11

    Question passing a Struct from one Form to another?

    lets say i have a group of variables in a Struct called Stats. i've made an instance of Stats, player, in Form1. How would i be able to use the same values of player in Form2?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Have Form2 get a reference or pointer to Form1 or make a reference or pointer to the struct in Form2 or make a new struct in Form2 and assign it from Form1.
    Possibilites are endless.
    Oh, and Cielo is using .NET, as well, so everyone is aware.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    11
    hm you may have misread that because i have no struct in form2, only form1. i want to be able to use the values of the struct from form1 in form2.

    and you said "make a new struct in Form2 and assign it from Form1," but thats exactly what i wanna know how to do... i wanna know how to assign values from Form1 into variables in Form2

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I'm going to move this to the Windows board since CLI and .NET are more about Windows than C++.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    How are form1 and form2 related?

    Pass the data from form1 to the parent when form1 closes, then to form2 when it is created.

    We need more info to tell you how to do this.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Something like this, Cielo:
    Code:
    class Form2
    {
        public Form2(struct Stats *pStats)
        {
            stats_ = pStats;
        }
    
        private struct Stats *stats_;
    };
    So when you create your form, you create it like this:
    Code:
    Form2 *form2 = new Form2(&stats); // assuming stats isn't already a pointer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Acessing a struct after passing to a function
    By bomberto in forum C++ Programming
    Replies: 5
    Last Post: 10-04-2006, 04:29 PM
  2. passing struct to function by reference
    By ironfistchamp in forum C++ Programming
    Replies: 11
    Last Post: 07-03-2006, 02:05 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Passing a struct
    By Drainy in forum C Programming
    Replies: 3
    Last Post: 03-14-2005, 11:02 AM
  5. passing struct to function help
    By staticalloc in forum C Programming
    Replies: 4
    Last Post: 10-06-2004, 08:30 AM