Date: Thu, 15 Aug 2002 20:19:12 +0200 Newsgroups: borland.public.delphi.vcl.components.using Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: Virtual Access by Atlantic Coast PLC, http://www.atlantic-coast.com/va Organization: TeamB Message-ID: Subject: Re: Graphics in a Thread From: "Peter Below (TeamB)" <100113.1101@compuXXserve.com> Reply-To: 100113.1101@compuXXserve.com References: <3d5b9d2c@dnews> NNTP-Posting-Host: 172.178.205.106 X-Trace: dnews 1029435262 172.178.205.106 (15 Aug 2002 11:14:22 -0700) Lines: 38 Path: dnews!not-for-mail Xref: dnews borland.public.delphi.vcl.components.using:102152 In article <3d5b9d2c@dnews>, John Cox wrote: > Suppose I have a TPanel (well, actually it is a TGraphicControl descendent, > but a TPanel will work for this discussion) on a form. I would like to > create a thread that draws on the canvas of the TPanel. You can think of > the project as an ocilloscope or spectrum analyzer. The thread would be > continually drawing on the canvas, and the use of any Synchronize() method > would certainly bog down the main thread. > > How can this be done? Can I pass the Canvas property to the Thread > constructor and use its methods to draw on it in the thread? You can, but only if you place the drawing code into a brace like Canvas.Lock; try ..drawing code finally Canvas.Unlock end The thread should not lock the canvas permanently. The least intrusive method would indeed be something like Peter MOrris' suggestion: have the thread first draw on an off-screen TBitmap or metafile, then use code like above to render the background image onto the canvas of the control. You don't need Synchronize if you lock the canvas during drawing operations. But of course you have to make sure the thread does not try to draw onto the control after the control has been destroyed when the form closes. -- Peter Below (TeamB)