?
Solved

Threads

Posted on 2004-08-18
4
Medium Priority
?
194 Views
Last Modified: 2010-04-05
How can I tell if my method is executed from the VCL thread or from another thread (a TThread descendant)?

procedure TFoo.Bar;
begin
  if InVclThread then
    This
  else
    That;
end;
0
Comment
Question by:__alex
  • 2
4 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 11829917
In your threads execute method, place a flag variable

var
 InVclThread : boolean

which you can set to true in the thread


then you can test it outside the thread


Shane
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 800 total points
ID: 11829939
function InVCLThread: Boolean;
begin
     Result:=GetWindowThreadProcessId(Application.Handle) = GetCurrentThreadId;
end;

should do :)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 11829942
procedure TMyClientThread.Execute;
begin
 //call your method here
 InVclThread:= True;
end;

Shane
0
 
LVL 2

Author Comment

by:__alex
ID: 11830080
Thanks Lee!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 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