We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,752 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Same code, different products? C++ Cli. Does not change values.

Okay, so almost the exact same code works in one of my c++/cli projects, but not the other. Both have the variables set as public, so they should be free to change. But only the first one does, and the second one does nothing.
Here's the button click code for the first.

1:

private: System::Void helium_Click(System::Object^  sender, System::EventArgs^  e) {
			   Form2^ form = gcnew Form2();
            form->Show();
			form->atomname->Text = "Helium";
			form->comionic->Text = "N/A";
			form->molmass->Text = "4.00 G/Mol";
			form->atomicnumber->Text = "2";
			form->color->Text = "Colorless";
			form->diatomic->Text = "Yes";
			form->pronounce->Text = "HEE-lee-am";
			form->mpoint->Text = "-272.20 °C";
			form->bpoint->Text = "-268.93 °C";
			form->tpoint->Text = "No Triple Point";
			form->state->Text = "Gas";
			form->adinfo->Text = "Helium naturally occurs as He2. It is a colorless, odorless gas. Helium has no"
				" common compounds, as any compounds made with Helium are extremely unstable at room temperature."
				" Uses include coolant in superconducting magnets, and since it is lighter than air, it is used"
				" to lift airships and balloons, it is also a vital component in rocket fuel.";
				
		 }

And the one that doesn't work.


2:

Info^ form = gcnew Info();
form->ShowDialog();
form->name->Text = "Calculator";
form->infobox->Text = "Test";

It just doesn't change the text at all. Any help? I can't see what I did wrong.

2
Contributors
2
Replies
10 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
valestrom
Junior Poster in Training
58 posts since Mar 2011
Reputation Points: 27
Solved Threads: 0
Skill Endorsements: 0

Your operations are out of order. Create a dialog object, initialize it, then show it:

Info^ form = nullptr;

try {
    form = gcnew Info();

    form->name->Text = "Calculator";
    form->infobox->Text = "Test";

    form->ShowDialog();
} finally {
    if (form != nullptr)
        form.Dispose();
}

This process makes the most sense from a code perspective, but it's especially important with ShowDialog(). From MSDN's page on Form.ShowDialog():

When this method is called, the code following it is not executed until after the dialog box is closed.

Narue
Bad Cop
Team Colleague
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54

Your operations are out of order. Create a dialog object, initialize it, then show it:

Info^ form = nullptr;

try {
    form = gcnew Info();

    form->name->Text = "Calculator";
    form->infobox->Text = "Test";

    form->ShowDialog();
} finally {
    if (form != nullptr)
        form.Dispose();
}

This process makes the most sense from a code perspective, but it's especially important with ShowDialog(). From MSDN's page on Form.ShowDialog():

Thanks Narue. Didn't quite pick up on this. But I completely understand what you mean.

valestrom
Junior Poster in Training
58 posts since Mar 2011
Reputation Points: 27
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0635 seconds using 2.73MB