[SOLVED] [C++/CLI Forms] Parse string from form1.h to form2.h

Hello, i need to parse one string or textbox to another form, but don't know how. Goal is i need this for locking button(disable button) when column in mysql != "specific string", i have login, after succesfully login user can see and use menu form and here i need specify when user mysqlspecificcolumns != "specific string" then make button->Enabled=false; but for this i need parse this string with loginname to SELECT ..FROM..WHERE name="specificstring" entered on first form (LoginScreen.h). i put code of this two forms(i have more but only this i need now) and when someone can help me, i've be really grateful.

And another question, when i include on form second form2 (#include "Form2.h) for example, then i can switch between forms with (this->hide(); form->Show()), but when i include on Form2 the first one(#include "Form1.h") the i see 5 errors with "form is undeclared, etc", how to fix this? thanks

<HlavnaObrazovka.h> - Menu(here when i include first loginscreen form, then i have errors like on this screnshot: http://prntscr.com/b0xula)

Last edited on
I can't see the screenshot - there is only a long list of tweets.

Normally there are 2 ways to pass a string to another form.

1. You create a constructor that can accept the string as a parameter
2. You define a public property in the form that can be set.

For the second problem. What is the name of the form? Is the form public?

Best would be if you could upload the whole project on Dropbox or somewhere else.
Thanks for reply, i upload my project to Google Drive, here is a link: https://drive.google.com/file/d/0BwfwTc3LEDDJVlhxemsxLWtmM2s/view?usp=sharing

I need parse string with priority number one, string name or String^ username from LoginScreen.h to HlavnaObrazovka.h. This is a started project for managing my gaming portal and this is utility for admins, first time doing CLI, everytime i make only console applications with mysql, etc.

Thanks a lot for help.
OK, I have had a look. This is what I would do to pass the username to the other form.
Add this code to HlavnaObrazovka.h
1
2
3
4
5
6
7
8
9
private:
    String^ m_UserName;
public:
  property String^ UserName
  {
     String^ get () {return m_UserName;}

    void set (String^ value) {m_UserName = value;}
  }


In loginscreen.h modify this:
1
2
3
4
5
6
 if (reader->GetString (0) == meno && reader->GetString (1) == heslo)
 {
    HlavnaObrazovka^ form = gcnew HlavnaObrazovka;
    form->UserName = meno; // pass username to form
    form->Show ();
 }


Hope it will work - I don't have MySql so I can't compile it.
Thanks man, you're an angel, next thing learned :) Thanks a lot, works like a charm.
Last edited on
You very welcome. Glad it works.
Hello, one plus question, can you please explain what error is this? I making file explorer where user need to find specific exe application and then form copy path string and use it to copy other files to directories in this folder where exe is located. when i make code and press button, i see this error http://prntscr.com/b1aei6 thanks a lot :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
private: System::Void button_zmenitadminheslo_Click(System::Object^  sender, System::EventArgs^  e) {
	IO::Stream^ myStream;
	OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

	if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
	{
		if ((myStream = openFileDialog1->OpenFile()) != nullptr)
		{
			String^ strfilename = openFileDialog1->InitialDirectory + openFileDialog1->FileName;
			MessageBox::Show(strfilename);
			myStream->Close();
		}
	}
}
It's working now, sorry for disturb :) Here is a fix, must put in main function in cpp class [STAThread] :) http://prntscr.com/b1ago8
Topic archived. No new replies allowed.