Solved

How can I access a Timage form a Tread safely?

Posted on 2009-04-04
3
435 Views
Last Modified: 2013-11-22
I have encountered a problem using VCL and Threads. I know Syncronize is must be used to access the components on the form (like SpinEdit etc) but how can I access an Image safely from a thread?  

(i have "Invalid pointer" errors randomly and this makes me feel the Image access can be the problem. )

Thank you
0
Comment
Question by:verjoz
  • 2
3 Comments
 
LVL 21

Expert Comment

by:developmentguru
ID: 24068690
 Normally you do not access the visual controls directly from the thread.  You set up synchronized events that the thread can fire.  From the response event within the form's code you then do what you need to, using the form's controls.

  One other thing to be careful of is the fact that some on screen controls use their own thread.  Trying to update such a control from within a synchronized call from another thread can cause problems.  Normally in this situation I make it easy on myself and use a simpler control.

  If you need more help it would help to know more about what you are trying to accomplish.
0
 

Author Comment

by:verjoz
ID: 24070885
Thank you for your response. I have to draw a picture coming from a USB camera to the Timage. So the steps:
- I get a buffer of the actual camera picture in (RGB format) in the thread
- I update it to the image1.picture.bitmap using the scanline pixel by pixel in the thread
- and finially I use the Image1.Refresh to appear the actual frame in the thread

How else can I solve it? And is it thread safe?

0
 
LVL 21

Accepted Solution

by:
developmentguru earned 500 total points
ID: 24072267
I would use the thread to translate the image to a TBitmap (within the thread).  When the translation is completed I would fire an event (within syncronize of course) passing the bitmap.  You can then assign the bitmap to the Image.Picture.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now