Page 1 of 1

canvas does not allow drawing

Posted: Sat Dec 22, 2012 3:51 pm
by mohsen24000
Hello dear,
when i use 'chat demo' in TIdUDPServer onRead event:

Code: Select all

procedure TfrmMain.UpdateChat(msg: string);
begin
  ParseString(mChat,msg); // from chat demo
  mChat.Invalidate;
try
  mChat.Format;
except
  mChat.FormatTail;
end;
  mChat.Update;
  mChat.DeleteUnusedStyles(True, True, True);
  mChat.VScrollPos:= mChat.VScrollMax;
end;
this error Sometimes appear:
"canvas does not allow drawing"
[/code][/b]

Posted: Sat Dec 22, 2012 4:06 pm
by Sergey Tkachenko
Is this code called in the context of the main thread?

Posted: Sat Dec 22, 2012 6:52 pm
by mohsen24000
Sergey Tkachenko wrote:Is this code called in the context of the main thread?
yes.

Posted: Sun Dec 23, 2012 2:14 pm
by Sergey Tkachenko
What's the value of ThreadedEvent property?
(sorry for double checking)

Posted: Sun Dec 23, 2012 2:27 pm
by mohsen24000
Oh!
It was True and change it False and all things right.
i think resolved.
Thanks a lot.
--------------------------------
Is it possible to correct this problem with Threads!?

Posted: Wed Dec 26, 2012 12:08 pm
by Sergey Tkachenko
VCL is not thread-safe, any drawing must be made in the context of the main process. This is not only for our components, this is a VCL design.
If you need to initiate redrawing from a thread, use Synchronize.