firefly2442
April 17th, 2005, 04:17 PM
Hello. I am working on a VC++ project. How can I pass information between forms in VC++ .NET? I need to get a URL from a textbox in one Form and then pass that to my main form. I tried making the component that will display it public and just access it that way but it says "Form1 is not a class or namespace name". Any thoughts or suggestions? Thanks! :)
g_gili
April 18th, 2005, 07:45 AM
Acctualy you want to get that message from that text box which is on other form like a (popop dialog?) You have to set a member variable than you call this.
in the mane program:
CYourDialog m_dialog;
m_dialog.yourmembervariable
I'm not sure that is works I'm not tested.
dumbquestion
April 18th, 2005, 02:48 PM
You could try a Singleton class (Search the net for more on Singletons). Put the following class in a header file that will be included in each form .h file:
public __gc class gl
{
private:
static gl * instance = new gl();
public:
static gl * getInstance(){return instance;}
static gl(){}
private:
gl(){}
public:
// Your global variables
double num;
String *urladdress;
};
For example, if in Form1 you want to set num = 23.1 with some button click, you would have this in your Form1.h file:
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
gl *GL = gl::getInstance();
GL->num = 23.1;
}
Then, in Form2, if you wanted to click a button to display the value of num in a MessageBox, you would have this in Form2.h:
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
gl *GL = gl::getInstance();
MessageBox::Show(Convert::ToString(GL->num));
}
Hope it helps!