Click to See Complete Forum and Search --> : error C2227


rowgram
November 8th, 2005, 04:12 PM
I can't figure out what 's wrong here :

Inside the 'tester' namespace, I've added textBox4 into Form2 :

tester::Form2::textBox4->set_Text("hi");

this gives me : Form2.h(650): error C2227: left of '->set_Text' must point to class/struct/union
type is ''


When I'm inside the Form2 class definition, I can use textBox4->set_Text without any problems; so how should I call Windows controls (like textboxes, buttons, etc..) outside of the definition of their Windows Form ??

Arie

NoHero
November 8th, 2005, 04:30 PM
tester::Form2::textBox4->set_Text("hi");

Hi Arie,

To access non-static members of your classes you must use the -> operator. Your Form classes are not a pure static class, thus you need to instance them before using their members. Otherwise you won't be able to have more than one Form2's:

tester::Form2 *myForm2 = new tester::Form2;

myForm2->textBox4->set_Text(S"hi");
myForm2->Show();


To tell your compiler to treat your string literal as a System::String (as needed for Managed C++) you need to put a "S" before it:

System::String sSample = S"A sample";

rowgram
November 8th, 2005, 05:58 PM
Thanks for the explaination.

It now tells me that myForm2 is an undeclared identifier (error C2065) - why does it treat myForm2 as a variable ?

I created myForm2 as outlined below : this was done inside an event handler of a button of the 'parent' form, Form1.

I'm making the myForm2->textbox statement inside a function belonging to tester namespace, and which is outside the definition of the Form2 class.

ak

NoHero
November 9th, 2005, 06:20 AM
Would you mind posting your code, and of course how your forms are named etc. This would help to better understand how your application is designed.

Thanks