🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17128

Re: Problem with Thread and OnPaint

#17128
From: Remy Lebeau (TeamB)
Date: Mon, 07 Apr 2003 04:29
26 lines
2341 bytes
It is hard to diagnose your problem without seeing yuor actual code.  But
offhand, it sounds like you are trying to draw directly onto the PaintBox
from your thread directly.  If so, then you shouldn't be doing that, as the
VCL is not thread-safe and can't handle cross-thread painting correctly.
Instead, you should be doing your thread-based drawing to a separate
in-memory bitmap that is properly protected by a synchronization object
(mutex, critical section, semaphore, etc), and then the thread can obtain
the lock to the bitmap when it needs to alter the bitmap, and then the
OnPaint event can obtain the lock when it needs to update the PaintBox with
the bitmap.  That way, only one is trying to access the bitmap at any given
time.


Gambit

"Phuoc Can HUA" <home+a+t+huaonline.com> wrote in message
news:3e90c1f3$1@newsgroups.borland.com...

> Now, when I move the main form over the form with the
> PaintBox very fast the image can't be restored properly. It looks
> like Windows can detect the 'invalid' area and only updates a
> small part of the PaintBox, although my procedure copies the
> entire image. That's OK. But the 'funny' thing is that the update
> segment sometimes appears at the wrong place, somtimes even
> somewhere on the screen (outside of the paintbox). Of course,
> sometimes it crashes as well :-(
Technical Details
Message-ID: <3e90fe9b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!news.linkpendium.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3e90c1f3$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,f582f476470f4983
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-04-06 21:35:50 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e90c1f3$1@newsgroups.borland.com>
Subject: Re: Problem with Thread and OnPaint
Date: Sun, 6 Apr 2003 21:29:29 -0700
Lines: 28
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3e90fe9b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1049689755 207.175.226.26 (6 Apr 2003 21:29:15 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!news.linkpendium.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail