Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How can I access a Timage form a Tread safely?

Posted on 2009-04-04
3
441 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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