1.11M Members

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

 
0
 

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.

 
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.

 
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():

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

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: