Please discuss general Delphi programming topics here.

Hello to all ..
I'm Italian and I help my brother for graduation ..
this is my first post .. sorry for my English!
I'm doing a program that controls a carriage with stepper motors ..
over carriage is an ultrasound probe that acquires data ..
ok everything works just talking to the I/O ports and synchronizing data (with several "sleep") crashes the GUI ..

Then I thought of a "thread" but I put everything in one "thread"? ..
Or only the elements that affect the interaction with the outside world (and thus block the GUI)?!

I would like to highlight the progress of the process (as a rendering in a 3D program) I would like to use a ProgressBar as well as black pixels already processed
Since the threads do not interact with the VCL .. What should I do?
Synchronize the thread with the VCL, or by separate thread?! And how to stop everything if I want to cancel the job?!

Here's my process (very macro) ..
The cycle goes through each pixel of the image (the image is a map of pressure that is a 256-color image obtained from another program and another process) ..

2. Find the color in the DB to find the correct angle of cutting
3. Position the probe (another long process and if I use a thread I have to go to the angke just found this thread)
4. wait "X" seconds before reading (pitching vibration) ..
6. wait "X" seconds
7. Turn OFF reading (get the value)
8. Black the pixel on trial and take forward the process bar ..

I do not care the detail, but a process to figure out which way to go ..

Thank you very much ..

dante3d
Member

Posts: 3
Joined: December 14th, 2010, 9:24 pm

Have you tried the Background Worker Component. I think by this component you can easily move your code in to a separate thread.

Besides the example included in the component's zip file, you can find another example at http://forum.delphiarea.com/viewtopic.php?f=7&t=1435.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Kambiz wrote:Have you tried the Background Worker Component. I think by this component you can easily move your code in to a separate thread.

Besides the example included in the component's zip file, you can find another example at http://forum.delphiarea.com/viewtopic.php?f=7&t=1435.

But I can't terminate the process ..

also using:
Code: Select all
BackGroundWorker.CancelBackGroundWorker.WaitFor

the process runs the same until the end
How to kill the process?

dante3d
Member

Posts: 3
Joined: December 14th, 2010, 9:24 pm

You have to check value of CancellationPending inside OnWork event, and exit the thread when cancel is requested.

Something like this:

Code: Select all
if Worker.CancellationPending thenbegin  Worker.AcceptCancellation;  Exit;end;

Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Ok
thanks

dante3d
Member

Posts: 3
Joined: December 14th, 2010, 9:24 pm