Page 1 of 1

Multithreading support

Posted: Tue Aug 22, 2006 1:25 pm
by dudubaiao
Does TRichView have support for multithreading?

I'm developing a DataSnap server application that generates RichViews on demand. If I call the remote method on 2 clients or more at the same time I get this error "Canvas does not allow drawing".

I'm not using the same TRichview for all method calls. Every method creates its own TRichView component. The only shared component is the TRVStyle.

Are there any workaround for it? I accept a sincronized-one-thread solution. :D

Thanks!

Posted: Wed Aug 23, 2006 12:26 pm
by Sergey Tkachenko
All operations that add items/remove/format/display document must be performed in the main thread. Use TThread.Synchronize method

Posted: Wed Aug 23, 2006 8:52 pm
by dudubaiao
I'm using a DataSnap Server, so the remote method are running on its own thread. To simplify the things I decided to use a Critical Section.
The code is show below:

Code: Select all

procedure TDataSnapServer.GenerateRichView;
begin

 CS.Acquire;

 try

    With TfrmGenerateRichView.Create(nil) do begin
       DoGenerate;
       Free;
    End;

 finally
    CS.Release;
 end;

end;
The Critical Section is working well, but sometimes, even when I'm running a single thread, I get the Canvas error... :(

Do you guys have any tip on how to solve this?

Thanks!

Posted: Thu Aug 24, 2006 3:21 am
by shmp
It looks like the creation of TfrmGenerateRichView have not really formated RichView. Wild guess.