Link to home
Start Free TrialLog in
Avatar of verjoz
verjoz

asked on

How can I access a Timage form a Tread safely?

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
Avatar of developmentguru
developmentguru
Flag of United States of America image

 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.
Avatar of verjoz
verjoz

ASKER

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?

ASKER CERTIFIED SOLUTION
Avatar of developmentguru
developmentguru
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial