Solved

closing threads

Posted on 2003-11-24
6
1,017 Views
Last Modified: 2011-09-20
How do I end a thread?

I used the sample code below to execute the thread:

procedure Form1.Button1CLick();
var vThread : Integer;
begin
      vThread := Thread.create(False);
end;

When I click Button2, the Thread should stop... How can I do that?
I thought of using ExitThread but I dont know how to use the GetExitCodeThread function to get the exit code of the thread.

PLease help... thanks
0
Comment
Question by:LORD_CHO
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
snehanshu earned 25 total points
ID: 9816084
To stop a thread,
  1) Buy ExEx premium services
  2) Search in Delphi TA for Thread stop
  3) Click on this link from the search results
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20390347.html

;-)
NOTE: 1 and 2 are now not required, may be for your next Q!

HTH,
...Snehanshu
0
 

Author Comment

by:LORD_CHO
ID: 9816774
hi ...Snehanshu
  thanks fo replying...

I did the example you have in your 3rd comment, but I always get "Access Violation" after executing the program. You see, my Thread (.execute) is located in Unit2...... But I am stopping it from unit1...
I have included the Unit2 in the uses of  Unit1... but still I receive the access violation.
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9817483
LORD_CHO,

  I do not know too much about threads, but can you provide code related to your thread in both units (of how you are creating and terminating )?
  I'll try, but if not me, others might be able to help.

...Shu
0
 
LVL 5

Assisted Solution

by:Hypoviax
Hypoviax earned 25 total points
ID: 9822557
Shehansu Hi seen you around alot lately,

Any way LORD_CHO how about you try wrapping a try except block around the code in Shehansu's code. This may help prevent the violation from occuring. Use the red dot things to trace the place where the violation is occuring but first of all use the try except. You will still see the error in delphi unless you turn stop on delphi exceptions off:

goto Tools-Debugger Options- Language Exceptions - Turn off stop on delphi exceptions

Regards,

Hypoviax
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

14 Experts available now in Live!

Get 1:1 Help Now