Windows Forms Application C++ .net 2003
-
-
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.
-
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.
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
-
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
-
Thank you very much for your reply but i need to user the same structure with the filled values in other form.
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
-
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
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:
-
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:
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