Solved

Threads

Posted on 2004-08-18
4
185 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 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

18 Experts available now in Live!

Get 1:1 Help Now