Solved

Threads

Posted on 2004-08-18
4
190 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
[X]
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
  • 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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…

737 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