0

The code below is from my form.. I declared a string GLOBALLY.. Then upon FormLoad, It inserts values for the string... When I do button click, the string is blank.. Why is it blank? Shouldnt the Values from FormLoad Event be in it? :

public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}
	public:
		System::String^ StringF;     //<-- Tried to declare my string globally..

and then I did:

public: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
		Form1::Visible = false;
		Query ^ F = gcnew Query();   //<-- Form 2 for input.
		F->ShowDialog();
		System::String^ StringF = F->textBox1->Text;  //<-- Set StringF as Value from text box!!!
                MessageBox::Show(StringF);  //<---- Tells me the string has values :)
}

public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                   System::String^ AddStr = "FFox - " + StringF;
                   IntPtr ptr2 = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(AddStr);
				 HWND FFox = FindWindow(0, (LPCSTR)ptr2.ToPointer());
				 if(FFox == NULL)
				 {
					 MessageBox::Show("Cant Find FF :(");
					 MessageBox::Show(StringF);     //<--- Tells me the string is blank!!  WHY?!?!

				 }

Edited by triumphost: n/a

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by jonsca
Featured Replies
  • 1
    jonsca 1,059   5 Years Ago

    Do your API call in a backgroundworker ([url]http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[/url]). It's the "easiest" way to do threading in .NET. The only thing is, you have to pass back your information to the GUI in a specific way (which I cannot remember right now). Read More

0

The StringF in Form1_Load() is a local variable, which masks the "global" (really it's a member of the Form1 class) variable. Remove the System::String ^ portion off of the one in Form1_Load and it should be all set.

Edited by jonsca: n/a

0

The StringF in Form1_Load() is a local variable, which masks the "global" (really it's a member of the Form1 class) variable. Remove the System::String ^ portion off of the one in Form1_Load and it should be all set.

Wow it worked thanks!! Although I tried that before and got some weird error.. Seems you may just be really good luck!

First post solved today :)


Also do u happen to know how to make my application constantly check if another app is open? Because I tried to add a loop but then my app stops responding. Maybe I added it in the wrong place :S

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.