[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Threads

Posted on 2004-08-18
4
Medium Priority
?
193 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 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