Click to See Complete Forum and Search --> : threads and gui - how to?


phenixa
June 23rd, 2008, 07:22 AM
hi,
i am new to c++ (used to program in java and c#)
for several days i have been trying to change gui from a thread,
i searched all the internet but couldnt find anything related,
i am using Borland c++ builder 6,

here is my code
hope
you ll find a solution

DWORD WINAPI TForm1::m_check(LPVOID param)
{
DWORD status;
HANDLE m_con[2];
m_con[0] = report;
m_con[1] = hExitEvent;
while(true)
{
status = WaitForMultipleObjects(2,m_con,FALSE,INFINITE);
Sleep(10); //do not use processor 100%
switch(status)
{
case WAIT_OBJECT_0:
Form1->write(message);
break;
case WAIT_OBJECT_0 +1:
return NULL;//exit

case WAIT_FAILED:
Form1->write("wait failed");
break;
default:
Form1->write("fail");
break;
}



}
}

this part is called by a thread when a button is clicked and runs
until exitevent is set
;

void TForm1::write(AnsiString inp)
{
Edit1->Text += inp+"\n";
}

and code to modify gui
this all code doesnt gives an error but it doesnt changes anything on gui

when i put a break point on
Edit->Text
as i see text is changed but it doesnt appears at gui

Marc G
June 23rd, 2008, 08:33 AM
I don't know much about borland C++, but you should probably not be calling methods directly on your GUI objects. Try to use PostMessage or Sendmessage to send messages to your GUI.

phenixa
June 23rd, 2008, 08:36 AM
Edit1->Text EQUALS NOT PLUS EQUALS
that was all about
Edit1->Text = mssage;
and it was okay
and thanks for reply Marc G

Marc G
June 23rd, 2008, 08:40 AM
Yes, but still, you will have to make sure that the borland form objects are thread safe before you start calling methods on it.

phenixa
June 23rd, 2008, 08:42 AM
you are right,
as i said i am new to borland,
i didn't have a problem so far,
hope, it is thread safe as u said,
i ll search for it..