-
June 23rd, 2008, 07:22 AM
#1
threads and gui - how to?
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
Code:
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
;
Code:
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
-
June 23rd, 2008, 08:33 AM
#2
Re: threads and gui - how to?
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.
-
June 23rd, 2008, 08:36 AM
#3
Re: threads and gui - how to?
Edit1->Text EQUALS NOT PLUS EQUALS
that was all about
Edit1->Text = mssage;
and it was okay
and thanks for reply Marc G
-
June 23rd, 2008, 08:40 AM
#4
Re: threads and gui - how to?
Yes, but still, you will have to make sure that the borland form objects are thread safe before you start calling methods on it.
-
June 23rd, 2008, 08:42 AM
#5
Re: threads and gui - how to?
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..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|