Solved

Threading in delphi

Posted on 2011-03-03
6
499 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
[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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

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

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Make the most of your online learning experience.
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 …
Six Sigma Control Plans
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 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