TThread WaitFor

Posted on 2005-04-22
Last Modified: 2012-05-05
I'm trying to figure out the useage of certain TThread methods.

Currently, i have 4 checkboxes, and a button.

on button click event i do

if CheckBox1.Checked then
 mode := 1;

if CheckBox2.Checked then
 mode := 2;


this doesn't seem to work out all that well.

how would i either

1) wait for each of the if statements to finish before moving onto the next one


2) wait for the thread to finish then move onto the next if statement..

i set globals in the if statements, as you can see, so unless there is a way to pass these in the call, how would you do that?

Question by:gwarguitar
    LVL 15

    Expert Comment

    I have never used threads before,  and Im SURE someone will be able to tell you how to do it, but I just wanted to ask if that is how you actually create a thread correctly.

    Is it not thread := TThread.Create(False) ?

    This seems to be a popular thread information source so hopefully you might be able to gleam some information from here

    LVL 1

    Accepted Solution

    If you want the thread to finish before conitinuing then why not forget about the thread and just put the code inline?

    Each if statement will finish before moving on to the next one: If the checkbox is checked then the process thread (the main program) will launch the thread (lets call it threadA)  and the process thread will move on to the next if statement. ThreadA will run when it gets a time slice.

    Note, Mike is right. You do need to create the thread as he suggests.

    Regarding the global variable you can pass it to the thread as a parameter. If you want to pass by reference you will need to set up critical sections inside the thread to access it. Otherwise pass itby value. To pass by value do this:

    TMyThread = class(TThread)
        myMode : Integer;
        constructor Create(ThisMode:Integer; ThisCreateSuspended:Boolean);

    constructor TMyThread.Create(ThisMode:Integer; ThisCreateSuspended:Boolean);
      inherited Create(true);
      myMode:= ThisMode;
      if (not ThisCreateSuspended) then
    end; {Create}


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    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…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    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…

    761 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

    13 Experts available now in Live!

    Get 1:1 Help Now