Solved

Threading in delphi

Posted on 2011-03-03
6
495 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn different types of Android Layout and some basics of an Android App.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

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