Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Newbie: About passing parameter into a form (http://www.go4expert.com/forums/newbie-passing-parameter-form-t790/)

kkyeung 7May2006 23:47

Newbie: About passing parameter into a form
 
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.

shabbir 8May2006 07:48

Re: Newbie: About passing parameter into a form
 
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.

kkyeung 8May2006 08:15

Re: Newbie: About passing parameter into a form
 
then, how could I change it in order to let the outside main see the SetParameter method and use it? thanks.

shabbir 8May2006 10:06

Re: Newbie: About passing parameter into a form
 
change Form *Form1 = new Form(); to Form1 *frm = new Form1();

kkyeung 8May2006 11:16

Re: Newbie: About passing parameter into a form
 
OK now, thanks a lot!

shabbir 8May2006 20:07

Re: Newbie: About passing parameter into a form
 
Quote:

Originally Posted by kkyeung
OK now, thanks a lot!

My pleasure.


All times are GMT +5.5. The time now is 19:03.