Solved

Threading in delphi

Posted on 2011-03-03
6
492 Views
Last Modified: 2012-05-11
Hello
Help me please

How can i make that application do anything with multi-threads.
Example : how can i make that program runs a work with 10 or more threads?

thanks
0
Comment
Question by:helyonprime96
6 Comments
 
LVL 14

Accepted Solution

by:
systan earned 500 total points
ID: 35029416
>>do anything with multi-threads.
?
I'm not sure the way you wanted, but you can look this project;
 multi-threading-progressbar.zip
and this one;
 delphi-thread-gui2.zip
and this database project too;
 adothreading.zip
0
 
LVL 3

Expert Comment

by:Freddy1990
ID: 35029445
The easiest way is sublassing the TThread class.

uses Classes;
type
  TMyThread = class(TThread)
  protected
    procedure Execute; override;
  public
    constructor Create;
    destructor Destroy; override;
  end;
...
procedure TMyThread.Create;
begin
  inherited Create(False);
  FreeOnTerminate := True;
end;

This example would start the thread instantly after creation and free it automatically on termination. You just put the code you want to execute in the Execute method.

If you want to interact with the main thread, you need to synchronize calls by adding a method to the thread without result or parameters and calling Synchronize on it, like Synchronize(Method);
0
 

Author Closing Comment

by:helyonprime96
ID: 35029477
thanks a lot!
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 3

Expert Comment

by:Freddy1990
ID: 35029500
Your welcome?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 35030312
wow, systan, you have found some really bad samples in threading
i didn't know samples like that existed

worst idea is to use (or reference) visual vcl objects from within a thread

never ever do that ... that's asking for trouble

helyonprime96,
do not ever (unless you really want trouble) put things like
fLabel: TLabel, fProgressbar: TProgressbar
inside a TThread class definition

you should have accepted Freddy1990's solution
as systan inidicated, she still needs to read a lot about threading ...

man, man, man, this is unbelievable ... another one will bite the dust when it comes to threading
0
 
LVL 14

Expert Comment

by:systan
ID: 35039230
the samples are from Delphi.About.com,
even you sometimes refereed that link, maybe.

there are many ways to drink the beer without getting drunk.


Sorry, if I am a bad expert, just as your article says? but I'm modest.


Now about your article here;
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/A_239-Displaying-progress-in-the-main-form-from-a-thread-in-Delphi.html


Will you correct the code of AdoThreading from delphi.about.com?
I know it's so easy for you, so lets see what is the difference and result of the code when it changes in your hands.
If this discussion is pointless then let it be.
Here's the code;
http://filedb.experts-exchange.com/incoming/2011/03_w10/416071/adothreading.zip
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

831 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