Newbie: About passing parameter into a form

kkyeung's Avatar, Join Date: May 2006
Light Poster
I have the following code, and I want to pass the variable test1 into the form, so that the form can read my test1 value. The var will be passed to SetParameter, a method under Form1. But I've encounted the following problem:

error C2664: 'void System::Windows::Forms::TextBox::set_Text(System:: String __gc *)' : cannot convert parameter 1 from 'int' to 'System::String __gc *'

error C2039: 'SetParameter' : is not a member of 'System::Windows::Forms::Form'


Form1.cpp main:
Code:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
int test1;
string line;
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
ifstream iFile("test.txt");

if (!iFile)
{
//error msg
return -1;
}

iFile >> test1;

iFile.close();

Form *Form1 = new Form();

Form1->SetParameter(test1); //put parameter into form

Application::Run(Form1); //run app
return 0;
}
Form1.h:

Code:
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1()
{
InitializeComponent();
}

void SetParameter(int t){
textBox1->Text = t;
}

protected:
void Dispose(Boolean disposing)......
.....
.....
.....
Actually I dunno where should I put the SetParameter, and how to convert int "t" to __gc textbox text as shown in the method.(since compiling the method results the first error)

Million thanks again.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You are creating an object of Type Form Form *Form1 = new Form(); but giving it just a name as Form1 but your class name is Form1 public __gc class Form1 : public System::Windows::Forms::Form and so SetParameter is a member of Form1 class and not Form class and thats why the error.
0
kkyeung's Avatar, Join Date: May 2006
Light Poster
then, how could I change it in order to let the outside main see the SetParameter method and use it? thanks.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
change Form *Form1 = new Form(); to Form1 *frm = new Form1();
0
kkyeung's Avatar, Join Date: May 2006
Light Poster
OK now, thanks a lot!
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by kkyeung
OK now, thanks a lot!
My pleasure.